Esempio 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))
Esempio 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))
Esempio n. 3
0
 def test_get_annotated_categories(self):
     categories = get_annotated_categories()
     self.assertEqual([(category.slug, category.post_count)
                       for category in categories], [('music', 2),
                                                     ('fun', 1)])
Esempio n. 4
0
 def test_get_annotated_categories(self):
     categories = get_annotated_categories()
     self.assertEqual(
             [(category.slug, category.post_count) for category in categories], 
             [('music', 2), ('fun', 1)]                
         )