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_tags(self):
     tags = get_annotated_tags()
     self.assertEqual([(tag.slug, tag.post_count) for tag in tags],
                      [('music', 2), ('signing', 1), ('fun', 1),
                       ('rock', 1), ('blues', 1)])
Exemplo n.º 4
0
 def test_get_annotated_tags(self):
     tags = get_annotated_tags()
     self.assertEqual(
             [(tag.slug, tag.post_count) for tag in tags], 
             [('music', 2), ('signing', 1), ('fun', 1), ('rock', 1), ('blues', 1)]
         )