mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Merge branch 'master' of http://opensource.washingtontimes.com/git/public/django-categories
This commit is contained in:
commit
3ea529c71b
3 changed files with 47 additions and 4 deletions
|
|
@ -102,4 +102,33 @@ def display_path_as_ul(category):
|
|||
cat = get_category(category)
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
class TopLevelCategoriesNode(template.Node):
|
||||
def __init__(self, varname):
|
||||
self.varname = varname
|
||||
|
||||
def render(self, context):
|
||||
context[self.varname] = Category.objects.filter(parent=None).order_by('name')
|
||||
return ''
|
||||
|
||||
|
||||
def get_top_level_categories(parser, token):
|
||||
"""
|
||||
Retrives an alphabetical list of all the categories with with no parents.
|
||||
|
||||
Syntax::
|
||||
|
||||
{% get_top_level_categories as categories %}
|
||||
|
||||
Returns an list of categories
|
||||
|
||||
"""
|
||||
bits = token.contents.split()
|
||||
if len(bits) != 3:
|
||||
raise template.TemplateSyntaxError, "Tag %s must have 2 arguments." % bits[0]
|
||||
if bits[1] != 'as':
|
||||
raise template.TemplateSyntaxError, "First argyment must be 'as'."
|
||||
return TopLevelCategoriesNode(bits[2])
|
||||
|
||||
register.tag(get_top_level_categories)
|
||||
|
|
@ -9,9 +9,6 @@ urlpatterns = patterns('django.views.generic.list_detail',
|
|||
url(
|
||||
r'^$', 'object_list', categorytree_dict, name='categories_tree_list'
|
||||
),
|
||||
#url(
|
||||
# r'^(?P<slug>[\w-]+)/$', 'object_detail', categorytree_dict, name='categories_tree'
|
||||
#),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('categories.views',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.template import RequestContext
|
||||
from categories.models import Category
|
||||
from django.views.decorators.cache import cache_page
|
||||
|
||||
def category_detail(request, slug, with_stories=False,
|
||||
template_name='categories/category_detail.html'):
|
||||
context = {}
|
||||
category = get_object_or_404(Category,
|
||||
slug__iexact=slug)
|
||||
|
||||
context['category'] = category
|
||||
|
||||
return render_to_response(template_name,
|
||||
context,
|
||||
context_instance=RequestContext(request)
|
||||
)
|
||||
Loading…
Reference in a new issue