Browse Source

Fix #1187

pull/1194/head
LeandroRoberto 8 years ago
parent
commit
8e3db9630b
  1. 12
      sapl/base/templatetags/common_tags.py
  2. 25
      sapl/crispy_layout_mixin.py
  3. 4
      sapl/materia/views.py
  4. 25
      sapl/templates/materia/proposicao_detail.html

12
sapl/base/templatetags/common_tags.py

@ -168,3 +168,15 @@ def search_get_model(object):
return 'n'
return None
@register.filter
def urldetail_content_type(obj, value):
return '%s:%s_detail' % (
value._meta.app_config.name, obj.content_type.model)
@register.filter
def urldetail(obj):
return '%s:%s_detail' % (
obj._meta.app_config.name, obj._meta.model_name)

25
sapl/crispy_layout_mixin.py

@ -1,12 +1,13 @@
from math import ceil
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.core.urlresolvers import reverse
from django.utils import formats
from django.utils.translation import ugettext as _
import rtyaml
def heads_and_tails(list_of_lists):
@ -77,29 +78,30 @@ def get_field_display(obj, fieldname):
else:
value = getattr(obj, fieldname)
str_type = str(type(value))
str_type_from_value = str(type(value))
str_type_from_field = str(type(field))
if value is None:
display = ''
elif 'date' in str_type:
elif 'date' in str_type_from_value:
display = formats.date_format(value, "SHORT_DATE_FORMAT")
elif 'bool' in str(type(value)):
elif 'bool' in str_type_from_value:
display = _('Sim') if value else _('Não')
elif 'ImageFieldFile' in str(type(value)):
if value:
display = '<img src="{}" />'.format(value.url)
else:
display = ''
elif 'FieldFile' in str(type(value)):
elif 'FieldFile' in str_type_from_value:
if value:
display = '<a href="{}">{}</a>'.format(
value.url,
value.name.split('/')[-1:][0])
else:
display = ''
elif 'ManyRelatedManager' in str(type(value))\
or 'RelatedManager' in str(type(value))\
or 'GenericRelatedObjectManager' in str(type(value)):
elif 'ManyRelatedManager' in str_type_from_value\
or 'RelatedManager' in str_type_from_value\
or 'GenericRelatedObjectManager' in str_type_from_value:
display = '<ul>'
for v in value.all():
display += '<li>%s</li>' % str(v)
@ -110,6 +112,13 @@ def get_field_display(obj, fieldname):
field.related_model._meta.verbose_name_plural)
elif hasattr(field, 'model'):
verbose_name = str(field.model._meta.verbose_name_plural)
elif 'GenericForeignKey' in str_type_from_field:
display = '<a href="{}">{}</a>'.format(
reverse(
'%s:%s_detail' % (
value._meta.app_config.name, obj.content_type.model),
args=(value.id,)),
value)
else:
display = str(value)
return verbose_name, display

4
sapl/materia/views.py

@ -21,7 +21,6 @@ from django.views.generic.base import RedirectView
from django.views.generic.edit import FormView
from django_filters.views import FilterView
import sapl
from sapl.base.models import Autor, CasaLegislativa
from sapl.comissoes.models import Comissao, Participacao
from sapl.compilacao.models import (STATUS_TA_IMMUTABLE_RESTRICT,
@ -42,6 +41,7 @@ from sapl.settings import EMAIL_SEND_USER
from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label,
autor_modal, gerar_hash_arquivo, get_base_url,
montar_row_autor)
import sapl
from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm,
AdicionarVariasAutoriasFilterSet, DespachoInicialForm,
@ -551,7 +551,7 @@ class ProposicaoCrud(Crud):
class BaseMixin(Crud.BaseMixin):
list_field_names = ['data_envio', 'data_recebimento', 'descricao',
'tipo']
'tipo', 'conteudo_gerado_related']
class BaseLocalMixin:
form_class = ProposicaoForm

25
sapl/templates/materia/proposicao_detail.html

@ -110,19 +110,30 @@
</div>
</div>
{% if object.materia_de_vinculo %}
<h2 class="legend">{% trans "Vínculo com a Matéria Legislativa" %}</h2>
<div class="row-fluid">
<div class="col-sm-12">
<div id="div_id_materia_de_vinculo" class="form-group">
{% if object.conteudo_gerado_related %}
<div class="col-sm-6">
<h2 class="legend">{% trans "Conteúdo Gerado" %}</h2>
<div id="div_id_conteudo_gerado_related" class="form-group">
<div class="controls">
<div class="form-control-static">{{object.materia_de_vinculo}}</div>
<div class="alert alert-info alert-dismissible fade in" role="alert">
<div >{{object.materia_de_vinculo.ementa}}</div>
<a href="{% url object|urldetail_content_type:object.conteudo_gerado_related object.id%}">
{{object.conteudo_gerado_related}}
</a>
</div>
</div>
</div>
{% endif %}
{% if object.materia_de_vinculo %}
<div class="col-sm-6">
<h2 class="legend">{% trans "Vínculo com a Matéria Legislativa" %}</h2>
<div id="div_id_materia_de_vinculo" class="form-group">
<div class="controls">
<a href="{% url object.materia_de_vinculo|urldetail object.materia_de_vinculo.id%}">
{{object.materia_de_vinculo}}
</a>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock detail_content %}

Loading…
Cancel
Save