1
"""Views for Zinnia categories"""
2
from django.shortcuts import get_object_or_404
3
from django.views.generic.list_detail import object_list
5
from zinnia.models import Category
6
from zinnia.settings import PAGINATION
9
def get_category_or_404(path):
10
"""Retrieve a Category by a path"""
11
path_bits = [p for p in path.split('/') if p]
12
return get_object_or_404(Category, slug=path_bits[-1])
15
def category_detail(request, path, page=None):
16
"""Display the entries of a category"""
17
category = get_category_or_404(path)
19
return object_list(request, queryset=category.entries_published_set(),
20
paginate_by=PAGINATION, page=page,
21
extra_context={'category': category})