Skip to content

Commit

Permalink
Added a num_children attribute to page objects in page menus.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmcd committed Jan 21, 2012
1 parent 5f5603d commit d98140e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mezzanine/pages/templatetags/pages_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def page_menu(context, token):
except KeyError:
user = None
slug = ""
has_children = lambda page_id: lambda: page_id in context["menu_pages"]
num_children = lambda id: lambda: len(context["menu_pages"][id])
has_children = lambda id: lambda: num_children(id)() > 0
published = Page.objects.published(for_user=user)
for page in published.select_related(depth=2).order_by("_order"):
page.set_menu_helpers(slug)
setattr(page, "num_children", num_children(page.id))
setattr(page, "has_children", has_children(page.id))
pages[page.parent_id].append(page)
context["menu_pages"] = pages
Expand Down

0 comments on commit d98140e

Please sign in to comment.