diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index 82092c696..1569ed6ba 100644 --- a/sapl/crispy_layout_mixin.py +++ b/sapl/crispy_layout_mixin.py @@ -4,7 +4,7 @@ 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.core.urlresolvers import reverse +from django.core.urlresolvers import reverse, reverse_lazy from django.utils import formats from django.utils.translation import ugettext as _ import rtyaml @@ -206,7 +206,16 @@ class CrispyLayoutFormMixin: def get_column(self, fieldname, span): obj = self.get_object() - verbose_name, text = get_field_display(obj, fieldname) + + func = None + if '|' in fieldname: + fieldname, func = tuple(fieldname.split('|')) + + if func: + verbose_name, text = getattr(self, func)(obj, fieldname) + else: + verbose_name, text = get_field_display(obj, fieldname) + return { 'id': fieldname, 'span': span, @@ -214,6 +223,52 @@ class CrispyLayoutFormMixin: 'text': text, } + def fk_urlize_for_detail(self, obj, fieldname): + + field = obj._meta.get_field(fieldname) + value = getattr(obj, fieldname) + + display = '{}'.format( + reverse( + '%s:%s_detail' % ( + value._meta.app_config.name, value._meta.model_name), + args=(value.id,)), + value) + + return field.verbose_name, display + + def m2m_urlize_for_detail(self, obj, fieldname): + + manager, fieldname = tuple(fieldname.split('__')) + + manager = getattr(obj, manager) + + verbose_name = manager.model._meta.verbose_name + display = '' + for item in manager.all(): + obj_m2m = getattr(item, fieldname) + + if obj == obj_m2m: + continue + + verbose_name = item._meta.get_field(fieldname).verbose_name + + display += '
  • {}
  • '.format( + reverse( + '%s:%s_detail' % ( + obj_m2m._meta.app_config.name, obj_m2m._meta.model_name), + args=(obj_m2m.id,)), + obj_m2m) + + display += '' + + if display: + display = '' % display + else: + verbose_name = '' + + return verbose_name, display + @property def layout_display(self): diff --git a/sapl/templates/crud/detail.html b/sapl/templates/crud/detail.html index 1653a11e4..513c67bbf 100644 --- a/sapl/templates/crud/detail.html +++ b/sapl/templates/crud/detail.html @@ -60,19 +60,20 @@ {% for row in fieldset.rows %}
    {% for column in row %} -
    -
    -

    {{ column.verbose_name }}

    -
    - {% comment %}TODO Transformar os links em URLs diretamente no CRUD{% endcomment %} - {% if column.text|url %} - - {% else %} -
    {{ column.text|safe|default:"" }}
    - {% endif %} + {% if column.verbose_name or column.text %} +
    +
    +

    {{ column.verbose_name }}

    +
    + {% if column.text|url %} + + {% else %} +
    {{ column.text|safe|default:"" }}
    + {% endif %} +
    -
    + {% endif %} {% endfor %}
    {% endfor %} diff --git a/sapl/templates/materia/layouts.yaml b/sapl/templates/materia/layouts.yaml index 4a86fe945..3dc086026 100644 --- a/sapl/templates/materia/layouts.yaml +++ b/sapl/templates/materia/layouts.yaml @@ -53,8 +53,8 @@ Anexada: AnexadaDetail: {% trans 'Matéria Anexada' %}: - - materia_principal - - materia_anexada + - materia_principal|fk_urlize_for_detail + - materia_anexada|fk_urlize_for_detail - data_anexacao data_desanexacao Autoria: @@ -137,6 +137,8 @@ MateriaLegislativaDetail: - data_apresentacao numero_protocolo tipo_apresentacao - texto_original - numeracao_set + - materia_anexada_set__materia_principal|m2m_urlize_for_detail + - materia_principal_set__materia_anexada|m2m_urlize_for_detail {% trans 'Outras Informações' %}: - apelido dias_prazo polemica - objeto regime_tramitacao em_tramitacao