Exemplo n.º 1
0
def blog_post_list(request, tag=None, category=None, author=None, month=None):
    """
        Displays a list of blog posts that are filtered by tag or category.
    """

    posts = Post.objects.published(for_user=request.user)

    if tag:
        tag = get_object_or_404(Tag, slug=tag)
        posts = posts.filter(tags__slug=tag.slug)
    if category:
        category = get_object_or_404(Category, slug=category)
        posts = posts.filter(category__slug=category.slug)
    if author:
        author = get_object_or_404(User, pk=author)
        posts = posts.filter(author=author)

    categories = get_annotated_categories()
    tags = get_annotated_tags()
    authors = get_annotated_authors()
    return render_to_response('blog/blog_post_list.html', {
        'posts': posts,
        'tag': tag,
        'author': author,
        'category': category,
        'categories': categories,
        'tags': tags,
        'authors': authors
    },
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def blog_post_list(request, tag=None, category=None, author=None, month=None):
    """
        Displays a list of blog posts that are filtered by tag or category.
    """
    
    posts = Post.objects.published(for_user=request.user)
    
    if tag:
        tag = get_object_or_404(Tag, slug=tag)
        posts = posts.filter(tags__slug=tag.slug)
    if category:
        category = get_object_or_404(Category, slug=category)
        posts = posts.filter(category__slug=category.slug)
    if author:
        author = get_object_or_404(User, pk=author)
        posts = posts.filter(author=author)

    categories = get_annotated_categories()
    tags = get_annotated_tags()
    authors = get_annotated_authors()
    return render_to_response('blog/blog_post_list.html', {
            'posts': posts,
            'tag': tag,
            'author': author,
            'category': category,
            'categories': categories,
            'tags': tags,
            'authors': authors
        }, context_instance=RequestContext(request))
Exemplo n.º 3
0
 def test_get_annotated_authors(self):
     authors = get_annotated_authors()
     self.assertEqual([(author.username, author.post_count)
                       for author in authors], [('marcofucci', 2),
                                                ('johndoe', 1)])
Exemplo n.º 4
0
 def test_get_annotated_authors(self):
     authors = get_annotated_authors()
     self.assertEqual(
             [(author.username, author.post_count) for author in authors], 
             [('marcofucci', 2), ('johndoe', 1)]
         )