Browse Source

Add default yaml source for subnav template tag

pull/202/head
Marcio Mazza 9 years ago
parent
commit
25ee869565
  1. 11
      base/templatetags/menus.py
  2. 2
      templates/comissoes/comissao_detail.html
  3. 2
      templates/sessao/sessaoplenaria_detail.html

11
base/templatetags/menus.py

@ -1,4 +1,4 @@
from os.path import dirname import os
import yaml import yaml
from django import template from django import template
@ -10,10 +10,13 @@ TEMPLATES_DIR = BASE_DIR.child("templates")
@register.inclusion_tag('menus/subnav.html', takes_context=True) @register.inclusion_tag('menus/subnav.html', takes_context=True)
def subnav(context, path): def subnav(context, path=None):
yaml_filename = TEMPLATES_DIR.child(*path.split('/')) obj = context['object']
if not path:
path = '%s/subnav.yaml' % obj.__class__._meta.app_label
yaml_filename = os.path.join(TEMPLATES_DIR, path)
menu = yaml.load(open(yaml_filename, 'r')) menu = yaml.load(open(yaml_filename, 'r'))
resolve_urls_inplace(menu, context['object'].pk) resolve_urls_inplace(menu, obj.pk)
return dict(menu=menu) return dict(menu=menu)

2
templates/comissoes/comissao_detail.html

@ -2,5 +2,5 @@
{% load menus %} {% load menus %}
{% block sections_nav %} {% block sections_nav %}
{% subnav "comissoes/subnav.yaml" %} {% subnav %}
{% endblock sections_nav %} {% endblock sections_nav %}

2
templates/sessao/sessaoplenaria_detail.html

@ -3,5 +3,5 @@
{% block actions %} {% endblock %} {% block actions %} {% endblock %}
{% block sections_nav %} {% block sections_nav %}
{% subnav "sessao/subnav.yaml" %} {% subnav %}
{% endblock sections_nav %} {% endblock sections_nav %}

Loading…
Cancel
Save