Browse Source

Refat. leitura de yaml's para internacionalização

- As leituras dos arquivos subnav.yaml e layouts.yaml foram
  refatoradas para suportar internacionalização.
- Falta fazer neste branch:
  - Mover todos os arquivos [app_label]/layouts.yaml para
    templates/[app_label]/layouts.yaml
  - aplicar a tag {% load i18n %} no início de todo arquivo layouts.yaml
  - aplicar a tag {% trans '' %} em todo texto a ser internacionalizado
  - DICA: deixe os ":" (dois pontos) de fora da tag trans.
pull/507/head
LeandroRoberto 9 years ago
parent
commit
b69ccfdfd7
  1. 3
      sapl/base/templatetags/menus.py
  2. 25
      sapl/crispy_layout_mixin.py
  3. 4
      sapl/templates/parlamentares/layouts.yaml
  4. 4
      sapl/templates/parlamentares/subnav.yaml

3
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

25
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 = '<a href="{}">{}</a>'.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):

4
sapl/parlamentares/layouts.yaml → sapl/templates/parlamentares/layouts.yaml

@ -1,6 +1,6 @@
{% load i18n %}
CargoMesa:
Cargo na Mesa:
{% trans 'Cargo na Mesa'%}:
- descricao:10 unico
Legislatura:

4
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

Loading…
Cancel
Save