def view_filter(**kwargs):
    """
    Filters blog posts by year/month/day, category, tag or author
    """
    from bambu_blog.models import Post, Category
    posts = Post.objects.select_related().live()
    if 'year' in kwargs:
        posts = posts.filter(date__year=int(kwargs['year']))
        if 'month' in kwargs:
            posts = posts.filter(date__month=int(kwargs['month']))
            if 'day' in kwargs:
                posts = posts.filter(date__day=int(kwargs['day']))
    if 'category' in kwargs:
        posts = posts.filter(categories__slug=kwargs['category'])
    elif 'tag' in kwargs:
        posts = posts.filter(tags__slug=kwargs['tag'])
    elif 'username' in kwargs:
        posts = posts.filter(author__username=kwargs['username'])
    return posts
