Browse Source

Propõe solução para TextFields com sequências longas

pull/2566/head
Leandro Roberto 7 years ago
parent
commit
3c05464414
  1. 13
      sapl/base/templatetags/common_tags.py
  2. 1
      sapl/crispy_layout_mixin.py
  3. 4
      sapl/templates/materia/materialegislativa_filter.html
  4. 7
      sapl/templates/sessao/blocos_resumo/materias_expediente.html
  5. 4
      sapl/templates/sessao/blocos_resumo/materias_ordem_dia.html
  6. 37
      sapl/utils.py
  7. 2
      sapl/webpack-stats.json

13
sapl/base/templatetags/common_tags.py

@ -1,3 +1,6 @@
from _functools import reduce
import re
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
@ -9,7 +12,6 @@ from sapl.norma.models import NormaJuridica
from sapl.parlamentares.models import Filiacao
from sapl.utils import filiacao_data, SEPARADOR_HASH_PROPOSICAO
register = template.Library()
@ -286,3 +288,12 @@ def render_chunk_vendors(extension=None):
return mark_safe('\n'.join(tags))
except:
return ''
@register.filter(is_safe=True)
@stringfilter
def dont_break_out(value):
_safe = '<div class="dont-break-out">{}</div>'.format(value)
_safe = mark_safe(_safe)
return _safe

1
sapl/crispy_layout_mixin.py

@ -166,6 +166,7 @@ def get_field_display(obj, fieldname):
value)
elif 'TextField' in str_type_from_field:
display = value.replace('\n', '<br/>')
display = '<div class="dont-break-out">{}</div>'.format(display)
else:
display = str(value)
return verbose_name, display

4
sapl/templates/materia/materialegislativa_filter.html

@ -1,6 +1,6 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load crispy_forms_tags common_tags%}
{% block actions %}
@ -48,7 +48,7 @@
<td>
<strong><a href="{% url 'sapl.materia:materialegislativa_detail' m.id %}">{{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}}</strong></a>
</br>
<strong>Ementa:</strong>&nbsp;{{ m.ementa|safe }}
<strong>Ementa:</strong>&nbsp;{{ m.ementa|dont_break_out }}
</br>
{% if m.data_apresentacao %}
<strong>Apresentação: </strong>{{ m.data_apresentacao }}

7
sapl/templates/sessao/blocos_resumo/materias_expediente.html

@ -1,3 +1,5 @@
{% load common_tags %}
<fieldset>
<legend>Matérias do Expediente</legend>
<table class="table table-striped table-hover">
@ -33,7 +35,10 @@
<b>Processo:</b> {{ m.numero_processo }}
{% endif %}
</td>
<td>{{m.ementa|safe}}<br/>{{m.observacao}}</td>
<td>
{{m.ementa|dont_break_out}}<br/>
{{m.observacao|dont_break_out}}
</td>
<td><b>{{m.resultado}}</b><br/>{{m.resultado_observacao}}</td>
</tr>
{% endfor %}

4
sapl/templates/sessao/blocos_resumo/materias_ordem_dia.html

@ -1,3 +1,5 @@
{% load common_tags %}
<fieldset>
<legend>Matérias da Ordem do Dia</legend>
<table class="table table-striped table-hover">
@ -33,7 +35,7 @@
<b>Processo:</b> {{ m.numero_processo }}
{% endif %}
</td>
<td>{{m.ementa|safe}}</b><br/>{{m.ementa_observacao}}</td>
<td>{{m.ementa|dont_break_out}}</b><br/>{{m.observacao|dont_break_out}}</td>
<td><b>{{m.resultado}}</b><br/>{{m.resultado_observacao}}</td>
</tr>
{% endfor %}

37
sapl/utils.py

@ -6,10 +6,6 @@ import re
from unicodedata import normalize as unicodedata_normalize
import unicodedata
from django.core.files.uploadedfile import UploadedFile
from django.forms import BaseForm
from sapl.crispy_layout_mixin import SaplFormHelper
from crispy_forms.layout import HTML, Button
from django import forms
from django.apps import apps
@ -18,11 +14,14 @@ from django.contrib import admin
from django.contrib.contenttypes.fields import (GenericForeignKey, GenericRel,
GenericRelation)
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import UploadedFile
from django.core.mail import get_connection
from django.db import models
from django.db.models import Q
from django.forms import BaseForm
from django.forms.widgets import SplitDateTimeWidget
from django.utils import six, timezone
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
import django_filters
from easy_thumbnails import source_generators
@ -31,9 +30,9 @@ import magic
from reversion_compare.admin import CompareVersionAdmin
from unipath.path import Path
from sapl.crispy_layout_mixin import SaplFormHelper
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row
# (26/10/2018): O separador foi mudador de '/' para 'K'
# por conta dos leitores de códigos de barra, que trocavam
# a '/' por '&' ou ';'
@ -44,6 +43,24 @@ def pil_image(source, exif_orientation=False, **options):
return source_generators.pil_image(source, exif_orientation, **options)
def split_longtext(value, max_part=50):
_safe = value.split()
def chunkstring(string):
return re.findall('.{%d}' % max_part, string)
def __map(a):
if len(a) <= max_part:
return a
return '<br>' + '<br>'.join(chunkstring(a))
_safe = map(__map, _safe)
_safe = ' '.join(_safe)
_safe = mark_safe(_safe)
return value
def clear_thumbnails_cache(queryset, field):
for r in queryset:
@ -84,7 +101,6 @@ autor_label = '''
</div>
'''
autor_modal = '''
<div id="modal_autor" title="Selecione o Autor" align="center">
<form>
@ -239,6 +255,7 @@ class RangeWidgetOverride(forms.MultiWidget):
class CustomSplitDateTimeWidget(SplitDateTimeWidget):
def render(self, name, value, attrs=None, renderer=None):
rendered_widgets = []
for i, x in enumerate(self.widgets):
@ -260,6 +277,7 @@ def register_all_models_in_admin(module_name, exclude_list=[]):
appname = appname[1] if appname[0] == 'sapl' else appname[0]
app = apps.get_app_config(appname)
for model in app.get_models():
class CustomModelAdmin(CompareVersionAdmin):
list_display = [f.name for f in model._meta.fields
if f.name != 'id' and f.name not in exclude_list]
@ -311,9 +329,11 @@ YES_NO_CHOICES = [(True, _('Sim')), (False, _('Não'))]
def listify(function):
@wraps(function)
def f(*args, **kwargs):
return list(function(*args, **kwargs))
return f
@ -351,7 +371,6 @@ LISTA_DE_UFS = [
RANGE_ANOS = [(year, year) for year in range(timezone.now().year + 1,
1889, -1)]
RANGE_MESES = [
(1, 'Janeiro'),
(2, 'Fevereiro'),
@ -431,8 +450,10 @@ def choice_force_optional(callable):
o item opcional '---------' que ChoiceFilter o adiciona, como dito
anteriormente.
"""
def _func():
return [('', '---------')] + callable()
return _func
@ -508,6 +529,7 @@ def fabrica_validador_de_tipos_de_arquivo(lista, nome):
raise ValidationError(_('Tipo de arquivo não suportado'))
except FileNotFoundError:
raise ValidationError(_('Arquivo não encontrado'))
# o nome é importante para as migrations
restringe_tipos_de_arquivo.__name__ = nome
return restringe_tipos_de_arquivo
@ -578,6 +600,7 @@ class NormaPesquisaOrderingFilter(django_filters.OrderingFilter):
class FileFieldCheckMixin(BaseForm):
def _check(self):
cleaned_data = super(FileFieldCheckMixin, self).clean()
errors = []

2
sapl/webpack-stats.json

@ -1 +1 @@
{"status":"done","publicPath":"/static/sapl/","chunks":{"chunk-vendors":[{"name":"css/chunk-vendors.3c9fe6b4.css","publicPath":"/static/sapl/css/chunk-vendors.3c9fe6b4.css","path":"../sapl/sapl/static/sapl/css/chunk-vendors.3c9fe6b4.css"},{"name":"js/chunk-vendors.0003dc37.js","publicPath":"/static/sapl/js/chunk-vendors.0003dc37.js","path":"../sapl/sapl/static/sapl/js/chunk-vendors.0003dc37.js"},{"name":"css/chunk-vendors.3c9fe6b4.css.map","publicPath":"/static/sapl/css/chunk-vendors.3c9fe6b4.css.map","path":"../sapl/sapl/static/sapl/css/chunk-vendors.3c9fe6b4.css.map"}],"compilacao":[{"name":"css/compilacao.3372b760.css","publicPath":"/static/sapl/css/compilacao.3372b760.css","path":"../sapl/sapl/static/sapl/css/compilacao.3372b760.css"},{"name":"js/compilacao.68b9eb03.js","publicPath":"/static/sapl/js/compilacao.68b9eb03.js","path":"../sapl/sapl/static/sapl/js/compilacao.68b9eb03.js"},{"name":"css/compilacao.3372b760.css.map","publicPath":"/static/sapl/css/compilacao.3372b760.css.map","path":"../sapl/sapl/static/sapl/css/compilacao.3372b760.css.map"}],"global":[{"name":"css/global.e4ae5421.css","publicPath":"/static/sapl/css/global.e4ae5421.css","path":"../sapl/sapl/static/sapl/css/global.e4ae5421.css"},{"name":"js/global.eb461386.js","publicPath":"/static/sapl/js/global.eb461386.js","path":"../sapl/sapl/static/sapl/js/global.eb461386.js"},{"name":"css/global.e4ae5421.css.map","publicPath":"/static/sapl/css/global.e4ae5421.css.map","path":"../sapl/sapl/static/sapl/css/global.e4ae5421.css.map"}],"painel":[{"name":"css/painel.baa845ab.css","publicPath":"/static/sapl/css/painel.baa845ab.css","path":"../sapl/sapl/static/sapl/css/painel.baa845ab.css"},{"name":"js/painel.f4adb91b.js","publicPath":"/static/sapl/js/painel.f4adb91b.js","path":"../sapl/sapl/static/sapl/js/painel.f4adb91b.js"},{"name":"css/painel.baa845ab.css.map","publicPath":"/static/sapl/css/painel.baa845ab.css.map","path":"../sapl/sapl/static/sapl/css/painel.baa845ab.css.map"}]}}
{"status":"done","publicPath":"http://localhost:8080/","chunks":{"compilacao":[{"name":"compilacao.js","publicPath":"http://localhost:8080/compilacao.js","path":"../sapl/sapl/static/sapl/compilacao.js"},{"name":"compilacao.js.map","publicPath":"http://localhost:8080/compilacao.js.map","path":"../sapl/sapl/static/sapl/compilacao.js.map"}],"global":[{"name":"global.js","publicPath":"http://localhost:8080/global.js","path":"../sapl/sapl/static/sapl/global.js"},{"name":"global.js.map","publicPath":"http://localhost:8080/global.js.map","path":"../sapl/sapl/static/sapl/global.js.map"}],"painel":[{"name":"painel.js","publicPath":"http://localhost:8080/painel.js","path":"../sapl/sapl/static/sapl/painel.js"},{"name":"painel.js.map","publicPath":"http://localhost:8080/painel.js.map","path":"../sapl/sapl/static/sapl/painel.js.map"}]}}
Loading…
Cancel
Save