Skip to content

Commit

Permalink
added missing templates for category traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
justquick committed Feb 26, 2010
1 parent 0ca025d commit 06d3352
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Meta:
def __unicode__(self):
ancestors = self.get_ancestors()
return ' > '.join([force_unicode(i.name) for i in ancestors]+[self.name,])

mptt.register(Category, order_insertion_by=['name'])


Expand Down
4 changes: 4 additions & 0 deletions categories/templates/categories/category_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h2>{{ category }}</h2>
{% if category.parent %}<h3>Go up to <a href="{{ category.parent.get_absolute_url }}">{{ category.parent }}</a></h3>{% endif %}
<p>{{ category.description }}</p>
{% if category.children.count %}<h3>Subcategories</h3><ul>{% for child in category.children.all %}<li><a href="{{ child.get_absolute_url }}">{{ child }}</a></li>{% endfor %}</ul>{% endif %}
2 changes: 2 additions & 0 deletions categories/templates/categories/category_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2>Categories</h2>
<ul>{% for category in object_list %}<li><a href="{{ category.get_absolute_url }}">{{ category }}</a></li>{% endfor %}</ul>
2 changes: 1 addition & 1 deletion categories/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from categories.models import Category

categorytree_dict = {
'queryset': Category.objects.all()
'queryset': Category.objects.filter(level=0)
}

urlpatterns = patterns('django.views.generic.list_detail',
Expand Down
27 changes: 13 additions & 14 deletions categories/views.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from categories.models import Category
from django.http import HttpResponse
from django.views.decorators.cache import cache_page
from django.core.urlresolvers import reverse
from django.template.loader import select_template
from categories.models import Category

@cache_page(3600)
def category_detail(request, path, with_stories=False,
template_name='categories/category_detail.html'):

path_items = path.strip('/').split('/')
slug = path_items[-1]
level = len(path_items)
context = {}
category = get_object_or_404(Category,
slug__iexact=slug, level=level-1)

context['category'] = category

return render_to_response(template_name,
context,
context_instance=RequestContext(request)
)
slug__iexact = path_items[-1],
level = len(path_items)-1)
template = select_template((
'categories/%s.html' % '_'.join(path_items),
template_name,
))
context = RequestContext(request)
context.update({'category':category})
return HttpResponse(template.render(context))

0 comments on commit 06d3352

Please sign in to comment.