Skip to content

Commit

Permalink
Merge pull request #2 from praekelt/feature/dont-modify-context
Browse files Browse the repository at this point in the history
Feature/dont modify context
  • Loading branch information
jbeyers authored Jan 26, 2017
2 parents 5689264 + 2525494 commit 5154bca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion navbuilder/templates/navbuilder/menu_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
{% load navbuilder_tags %}

{% block content %}
{% render_menu object %}
{% render_menu object.slug %}
{% endblock %}
2 changes: 1 addition & 1 deletion navbuilder/templates/navbuilder/menu_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

{% block content %}
{% for object in object_list %}
{% render_menu object %}
{% render_menu object.slug %}
{% endfor %}
{% endblock %}
22 changes: 11 additions & 11 deletions navbuilder/templatetags/navbuilder_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
)
def render_menu(context, slug):
try:
context["object"] = Menu.objects.get(slug=slug)
return {"object": Menu.objects.get(slug=slug)}
except Menu.DoesNotExist:
pass
return context
return {}


@register.inclusion_tag(
"navbuilder/inclusion_tags/menuitem_detail.html", takes_context=True
)
def render_menuitem(context, obj):
context["object"] = obj
return context
return {"object": obj}


@register.inclusion_tag(
Expand All @@ -37,9 +36,10 @@ def navbuilder_breadcrumbs(context, slug):
prefer the main menu structure. This also allows us to construct
breadcrumbs for items that don't show up in page menus at all.
"""
context["navbuilder_breadcrumbs"] = []
di = {}
di["navbuilder_breadcrumbs"] = []
if "object" not in context:
return context
return {}

def get_menuitems(item):
if item.parent:
Expand All @@ -59,12 +59,12 @@ def get_menuitems(item):
for crumb_set in crumb_sets:
menu = crumb_set[0].menu
if menu and menu.slug == slug:
context["navbuilder_breadcrumbs"] = crumb_set
di["navbuilder_breadcrumbs"] = crumb_set

if not context["navbuilder_breadcrumbs"]:
if not di["navbuilder_breadcrumbs"]:
if crumb_sets:
context["navbuilder_breadcrumbs"] = crumb_sets[0]
di["navbuilder_breadcrumbs"] = crumb_sets[0]
else:
context["navbuilder_breadcrumbs"] = []
di["navbuilder_breadcrumbs"] = []

return context
return di

0 comments on commit 5154bca

Please sign in to comment.