mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
25 lines
No EOL
965 B
Python
25 lines
No EOL
965 B
Python
from django.shortcuts import get_object_or_404, render_to_response
|
|
from django.template import RequestContext
|
|
from django.http import HttpResponse
|
|
from django.views.decorators.cache import cache_page
|
|
from django.template.loader import select_template
|
|
from categories.models import Category
|
|
from settings import CACHE_VIEW_LENGTH
|
|
|
|
@cache_page(CACHE_VIEW_LENGTH)
|
|
def category_detail(request, path, with_stories=False,
|
|
template_name='categories/category_detail.html'):
|
|
path_items = path.strip('/').split('/')
|
|
category = get_object_or_404(Category,
|
|
slug__iexact = path_items[-1],
|
|
level = len(path_items)-1)
|
|
|
|
templates = []
|
|
while path_items:
|
|
templates.append('categories/%s.html' % '_'.join(path_items))
|
|
path_items.pop()
|
|
templates.append(template_name)
|
|
|
|
context = RequestContext(request)
|
|
context.update({'category':category})
|
|
return HttpResponse(select_template(templates).render(context)) |