Browse Source

Fix #1608

pull/1610/head
LeandroRoberto 7 years ago
parent
commit
87b2f9290b
  1. 57
      sapl/crispy_layout_mixin.py
  2. 3
      sapl/templates/crud/detail.html
  3. 6
      sapl/templates/materia/layouts.yaml

57
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()
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 = '<a href="{}">{}</a>'.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 += '<li><a href="{}">{}</a></li>'.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 = '<ul>%s</ul>' % display
else:
verbose_name = ''
return verbose_name, display
@property
def layout_display(self):

3
sapl/templates/crud/detail.html

@ -60,11 +60,11 @@
{% for row in fieldset.rows %}
<div class="row-fluid">
{% for column in row %}
{% if column.verbose_name or column.text %}
<div class="col-sm-{{ column.span }}">
<div id="div_id_{{ column.id }}" class="form-group">
<p class="control-label">{{ column.verbose_name }}</p>
<div class="controls">
{% comment %}TODO Transformar os links em URLs diretamente no CRUD{% endcomment %}
{% if column.text|url %}
<div class="form-control-static"><a href="{{ column.text|safe }}"> {{ column.text|safe|default:"" }} </a></div>
{% else %}
@ -73,6 +73,7 @@
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}

6
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

Loading…
Cancel
Save