Source

gnocchi-blog / gnocchi / blog / templatetags / blog.py

Full commit
from django import template
from gnocchi.blog.models import Post

register = template.Library()

@regiser.assignment_tag
def get_recent_posts(count, username=None, *tags, **kwargs):
    tags = filter(None, tags)
    qset = Post.objects.current()
    for tag in tags:
        qset = qset.filter(tags__name=tag)
    if username:
        qset = qset.filter(posted_bt__username=username)
    return qset

@register.filter
def recent_posts(value, username=None):
    qset = Post.objects.current()
    if username:
        qset.filter(posted_by__username=username)
    try:
        return qset[:int(value)]
    except Post.DoesNotExist:
        return []