From 3932df025f9b56adafc8013ca769e9aa70b051d7 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Mon, 1 Feb 2016 17:20:19 -0200 Subject: [PATCH] Add subnav template tag --- base/templatetags/menus.py | 28 ++++++++++++ templates/menus/subnav.html | 20 +++++++++ templates/sessao/sessaoplenaria_detail.html | 47 ++------------------- templates/sessao/subnav.yaml | 32 ++++++++++++++ 4 files changed, 83 insertions(+), 44 deletions(-) create mode 100644 base/templatetags/menus.py create mode 100644 templates/menus/subnav.html create mode 100644 templates/sessao/subnav.yaml diff --git a/base/templatetags/menus.py b/base/templatetags/menus.py new file mode 100644 index 000000000..61b9d3a0a --- /dev/null +++ b/base/templatetags/menus.py @@ -0,0 +1,28 @@ +from os.path import dirname + +import yaml +from django import template +from django.core.urlresolvers import reverse +from sapl.settings import BASE_DIR + +register = template.Library() +TEMPLATES_DIR = BASE_DIR.child("templates") + + +@register.inclusion_tag('menus/subnav.html', takes_context=True) +def subnav(context, path): + yaml_filename = TEMPLATES_DIR.child(*path.split('/')) + menu = yaml.load(open(yaml_filename, 'r')) + resolve_urls_inplace(menu, context['object'].pk) + return dict(menu=menu) + + +def resolve_urls_inplace(menu, pk): + if isinstance(menu, list): + for item in menu: + resolve_urls_inplace(item, pk) + else: + if 'url' in menu: + menu['url'] = reverse(menu['url'], kwargs={'pk': pk}) + if 'children' in menu: + resolve_urls_inplace(menu['children'], pk) diff --git a/templates/menus/subnav.html b/templates/menus/subnav.html new file mode 100644 index 000000000..bb74daf48 --- /dev/null +++ b/templates/menus/subnav.html @@ -0,0 +1,20 @@ +{% load i18n %} + diff --git a/templates/sessao/sessaoplenaria_detail.html b/templates/sessao/sessaoplenaria_detail.html index 0932ca317..83f819c02 100644 --- a/templates/sessao/sessaoplenaria_detail.html +++ b/templates/sessao/sessaoplenaria_detail.html @@ -1,48 +1,7 @@ {% extends "crud/detail.html" %} -{% load i18n %} +{% load i18n menus %} {% block actions %} {% endblock %} -{% block sections_nav %} - - +{% block sections_nav %} + {% subnav "sessao/subnav.yaml" %} {% endblock sections_nav %} diff --git a/templates/sessao/subnav.yaml b/templates/sessao/subnav.yaml new file mode 100644 index 000000000..09682f81a --- /dev/null +++ b/templates/sessao/subnav.yaml @@ -0,0 +1,32 @@ +- title: Abertura + children: + - title: Dados Básicos + url: sessaoplenaria:detail + - title: Mesa + url: sessaoplenaria:mesa + - title: Presença + url: sessaoplenaria:presenca + - title: Explicações Pessoais + url: sessaoplenaria:explicacao + +- title: Expedientes + children: + - title: Expediente Diversos + url: sessaoplenaria:expediente + - title: Matérias Expediente + url: sessaoplenaria:expedienteordemdia_list + - title: Oradores do Expediente + url: sessaoplenaria:oradorexpediente + +- title: Ordem do Dia + children: + - title: Matérias Ordem do Dia + url: sessaoplenaria:materiaordemdia_list + - title: Presença Ordem do Dia + url: sessaoplenaria:presencaordemdia + +- title: Painel Eletrônico + url: sessaoplenaria:painel + +- title: Resumo + url: sessaoplenaria:resumo