diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index 3cbf5e46c..3d208e86b 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -1,6 +1,10 @@ -import yaml from django import template from django.core.urlresolvers import reverse +from django.utils.translation import ugettext_lazy as _ +import yaml + +from sapl.utils import sapl_logger + register = template.Library() @@ -28,7 +32,7 @@ def subnav(context, path=None): if obj: root_pk = obj.pk - if root_pk: + if root_pk or 'subnav_template_name' in context: request = context['request'] """ @@ -64,7 +68,11 @@ def subnav(context, path=None): menu = yaml.load(rendered) resolve_urls_inplace(menu, root_pk, rm, context) except Exception as e: - print(e) + sapl_logger.error(_("""Erro na conversão do yaml %s. App: %s. + Erro: + %s + """) % ( + yaml_path, rm.app_name, str(e))) return {'menu': menu} @@ -81,6 +89,7 @@ def resolve_urls_inplace(menu, pk, rm, context): return list_active else: if 'url' in menu: + url_name = menu['url'] if 'check_permission' in menu and not context[ @@ -88,16 +97,27 @@ def resolve_urls_inplace(menu, pk, rm, context): menu['url'] = '' menu['active'] = '' else: - menu['url'] = reverse( - '%s:%s' % (rm.app_name, menu['url']), kwargs={'pk': pk}) + if ':' in url_name: + try: + menu['url'] = reverse('%s' % menu['url'], + kwargs={'pk': pk}) + except: + menu['url'] = reverse('%s' % menu['url']) + else: + try: + menu['url'] = reverse('%s:%s' % ( + rm.app_name, menu['url']), kwargs={'pk': pk}) + except: + menu['url'] = reverse('%s:%s' % ( + rm.app_name, menu['url'])) + menu['active'] = 'active'\ if context['request'].path == menu['url'] else '' - if not menu['active']: """ Se não encontrada diretamente, procura a url acionada dentro do crud, caso seja um. - Serve para manter o active no suvnav correto ao acionar + Serve para manter o active no subnav correto ao acionar as funcionalidades diretas do MasterDetailCrud, como: - visualização de detalhes, adição, edição, remoção. """ diff --git a/sapl/materia/views.py b/sapl/materia/views.py index afb370712..083b3ede1 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1336,6 +1336,8 @@ class PrimeiraTramitacaoEmLoteView(PermissionRequiredMixin, FilterView): context = super(PrimeiraTramitacaoEmLoteView, self).get_context_data(**kwargs) + context['subnav_template_name'] = 'materia/em_lote/subnav_em_lote.yaml' + # Verifica se os campos foram preenchidos if not self.filterset.form.is_valid(): return context diff --git a/sapl/templates/materia/em_lote/acessorio.html b/sapl/templates/materia/em_lote/acessorio.html index 5b4528bca..6fae58731 100644 --- a/sapl/templates/materia/em_lote/acessorio.html +++ b/sapl/templates/materia/em_lote/acessorio.html @@ -1,7 +1,6 @@ {% extends "crud/detail.html" %} {% load i18n crispy_forms_tags %} {% block actions %}{% endblock %} -{% block sections_nav %}{% endblock %} {% block detail_content %} {% if not filter_url %} diff --git a/sapl/templates/materia/em_lote/subnav.html b/sapl/templates/materia/em_lote/subnav.html deleted file mode 100644 index 1ba0fe431..000000000 --- a/sapl/templates/materia/em_lote/subnav.html +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/sapl/templates/materia/em_lote/subnav_em_lote.yaml b/sapl/templates/materia/em_lote/subnav_em_lote.yaml new file mode 100644 index 000000000..3469c9262 --- /dev/null +++ b/sapl/templates/materia/em_lote/subnav_em_lote.yaml @@ -0,0 +1,5 @@ +{% load i18n common_tags %} +- title: {% trans 'Primeira Tramitação' %} + url: primeira_tramitacao_em_lote +- title: {% trans 'Tramitação em Lote' %} + url: tramitacao_em_lote diff --git a/sapl/templates/materia/em_lote/tramitacao.html b/sapl/templates/materia/em_lote/tramitacao.html index a8fb49df5..b9845f55b 100644 --- a/sapl/templates/materia/em_lote/tramitacao.html +++ b/sapl/templates/materia/em_lote/tramitacao.html @@ -1,7 +1,6 @@ {% extends "crud/detail.html" %} {% load i18n crispy_forms_tags %} {% block actions %}{% endblock %} -{% block sections_nav %} {% include 'materia/em_lote/subnav.html'%} {% endblock sections_nav %} {% block detail_content %} {% if not filter_url %} diff --git a/sapl/utils.py b/sapl/utils.py index 05eed3457..d4e7bed3f 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,9 +1,9 @@ -import hashlib from datetime import date from functools import wraps from unicodedata import normalize as unicodedata_normalize +import hashlib +import logging -import magic from django import forms from django.apps import apps from django.conf import settings @@ -14,6 +14,11 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied, ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput +import magic +from sapl.settings import BASE_DIR + + +sapl_logger = logging.getLogger(BASE_DIR.name) def normalize(txt):