Skip to content

Commit

Permalink
Fixed small errors in templatetags documentation and docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramiro Morales authored and coordt committed May 8, 2011
1 parent 7119ca8 commit 1100ad3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
72 changes: 36 additions & 36 deletions categories/templatetags/category_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ def get_category(category_string):
category = category_string[1:-1]
else:
category = category_string

if category.startswith('/'):
category = category[1:]
if category.endswith('/'):
category = category[:-1]

cat_list = category.split('/')
if len(cat_list) == 0:
return None
try:
categories = Category.objects.filter(name = cat_list[-1], level=len(cat_list)-1)
if len(cat_list) == 1 and len(categories) > 1:
return None
# If there is only one, use it. If there is more than one, check
# If there is only one, use it. If there is more than one, check
# if the parent matches the parent passed in the string
if len(categories) == 1:
return categories[0]
Expand All @@ -42,11 +42,11 @@ def get_category(category_string):


class CategoryDrillDownNode(template.Node):

def __init__(self, category, varname):
self.category = template.Variable(category)
self.varname = varname

def render(self, context):
try:
category = self.category.resolve(context)
Expand All @@ -66,21 +66,21 @@ def get_category_drilldown(parser, token):
"""
Retrieves the specified category, its ancestors and its immediate children
as an iterable.
Syntax::
{% get_category_drilldown "category name" as varname %}
Example::
{% get_category_drilldown "/Grandparent/Parent" as family %}
or ::
{% get_category_drilldown category_obj as family %}
Sets family to::
Grandparent, Parent, Child 1, Child 2, Child n
"""
bits = token.contents.split()
Expand All @@ -95,32 +95,32 @@ def get_category_drilldown(parser, token):
@register.inclusion_tag('categories/breadcrumbs.html')
def breadcrumbs(category,separator="/"):
"""
Render breadcrumbs, using the ``categories/breadcrumbs.html`` template,
Render breadcrumbs, using the ``categories/breadcrumbs.html`` template,
using the optional ``separator`` argument.
"""
if isinstance(category, Category):
cat = category
else:
cat = get_category(category)

return {'category': cat, 'separator': separator}

@register.inclusion_tag('categories/ul_tree.html')
def display_drilldown_as_ul(category):
"""
Render the category with ancestors, but no children using the
Render the category with ancestors and children using the
``categories/ul_tree.html`` template.
Example::
{% display_drilldown_as_ul "/Grandparent/Parent" %}
or ::
{% display_drilldown_as_ul category_obj %}
Returns::
<ul>
<li><a href="/categories/">Top</a>
<ul>
Expand All @@ -143,25 +143,25 @@ def display_drilldown_as_ul(category):
cat = category
else:
cat = get_category(category)

return {'category': cat, 'path': drilldown_tree_for_node(cat) or []}

@register.inclusion_tag('categories/ul_tree.html')
def display_path_as_ul(category):
"""
Render the category with ancestors, but no children using the
Render the category with ancestors, but no children using the
``categories/ul_tree.html`` template.
Example::
{% display_path_as_ul "/Grandparent/Parent" %}
or ::
{% display_path_as_ul category_obj %}
Returns::
<ul>
<li><a href="/categories/">Top</a>
<ul>
Expand All @@ -174,26 +174,26 @@ def display_path_as_ul(category):
cat = category
else:
cat = get_category(category)

return {'category': cat, 'path': cat.get_ancestors() or []}

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 ''

@register.tag
def get_top_level_categories(parser, token):
"""
Retrieves an alphabetical list of all the categories with with no parents.
Retrieves an alphabetical list of all the categories that have no parents.
Syntax::
{% get_top_level_categories as categories %}
Returns an list of categories [<category>, <category>, <category, ...]
"""
bits = token.contents.split()
Expand Down
6 changes: 3 additions & 3 deletions doc_src/templatetags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Template Tags
get_top_level_categories
========================

Retrieves an alphabetical list of all the categories.
Retrieves an alphabetical list of all the categories that have no parents.

Syntax:

.. code-block:: django
{% get_top_level_categories as categories %}
Returns an list of categories ``[<category>, <category>, <category, ...]``


Expand Down Expand Up @@ -72,7 +72,7 @@ Sets ``family`` to::
display_drilldown_as_ul
=======================

Render the category with ancestors, but no children using the
Render the category with ancestors and children using the
``categories/ul_tree.html`` template.

Example:
Expand Down

0 comments on commit 1100ad3

Please sign in to comment.