diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index ce67143ea..5dda6f104 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -43,7 +43,8 @@ def subnav(context, path=None): A função nativa abaixo busca em todos os Loaders Configurados. """ yaml_template = template.loader.get_template(yaml_path) - menu = yaml.load(open(yaml_template.origin.name, 'r')) + rendered = yaml_template.render() + menu = yaml.load(rendered) resolve_urls_inplace(menu, root_pk, app, context) except: pass diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index ad079f66a..638efecf5 100644 --- a/sapl/crispy_layout_mixin.py +++ b/sapl/crispy_layout_mixin.py @@ -1,12 +1,13 @@ from math import ceil from os.path import dirname, join -import rtyaml from crispy_forms.bootstrap import FormActions from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit +from django import template from django.utils import formats from django.utils.translation import ugettext as _ +import rtyaml def heads_and_tails(list_of_lists): @@ -70,8 +71,8 @@ def get_field_display(obj, fieldname): elif 'FieldFile' in str(type(value)): if value: display = '{}'.format( - value.url, - value.name.split('/')[-1:][0]) + value.url, + value.name.split('/')[-1:][0]) else: display = '' else: @@ -89,10 +90,8 @@ class CrispyLayoutFormMixin: return self.model.__name__ def get_layout(self): - filename = join( - dirname(self.model._meta.app_config.models_module.__file__), - 'layouts.yaml') - return read_layout_from_yaml(filename, self.layout_key) + yaml_layout = '%s/layouts.yaml' % self.model._meta.app_config.label + return read_layout_from_yaml(yaml_layout, self.layout_key) @property def fields(self): @@ -146,15 +145,17 @@ class CrispyLayoutFormMixin: } for legend, rows in heads_and_tails(self.get_layout())] -def read_yaml_from_file(filename): +def read_yaml_from_file(yaml_layout): + # TODO cache this at application level - with open(filename, 'r') as yamlfile: - return rtyaml.load(yamlfile) + t = template.loader.get_template(yaml_layout) + rendered = t.render() + return rtyaml.load(rendered) -def read_layout_from_yaml(filename, key): +def read_layout_from_yaml(yaml_layout, key): # TODO cache this at application level - yaml = read_yaml_from_file(filename) + yaml = read_yaml_from_file(yaml_layout) base = yaml[key] def line_to_namespans(line): diff --git a/sapl/parlamentares/layouts.yaml b/sapl/templates/parlamentares/layouts.yaml similarity index 97% rename from sapl/parlamentares/layouts.yaml rename to sapl/templates/parlamentares/layouts.yaml index 866a791f9..f3fc6fc54 100644 --- a/sapl/parlamentares/layouts.yaml +++ b/sapl/templates/parlamentares/layouts.yaml @@ -1,6 +1,6 @@ - +{% load i18n %} CargoMesa: - Cargo na Mesa: + {% trans 'Cargo na Mesa'%}: - descricao:10 unico Legislatura: diff --git a/sapl/templates/parlamentares/subnav.yaml b/sapl/templates/parlamentares/subnav.yaml index fc171ea84..aa8bcc7a0 100644 --- a/sapl/templates/parlamentares/subnav.yaml +++ b/sapl/templates/parlamentares/subnav.yaml @@ -1,4 +1,5 @@ -- title: Início +{% load i18n %} +- title: {% trans 'Início' %} url: parlamentar_detail - title: Mandatos url: mandato_list @@ -6,4 +7,3 @@ url: filiacao_list - title: Dependentes url: dependente_list -