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 import template
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe 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.parlamentares.models import Filiacao
from sapl.utils import filiacao_data, SEPARADOR_HASH_PROPOSICAO from sapl.utils import filiacao_data, SEPARADOR_HASH_PROPOSICAO
register = template.Library() register = template.Library()
@ -286,3 +288,12 @@ def render_chunk_vendors(extension=None):
return mark_safe('\n'.join(tags)) return mark_safe('\n'.join(tags))
except: except:
return '' 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) value)
elif 'TextField' in str_type_from_field: elif 'TextField' in str_type_from_field:
display = value.replace('\n', '<br/>') display = value.replace('\n', '<br/>')
display = '<div class="dont-break-out">{}</div>'.format(display)
else: else:
display = str(value) display = str(value)
return verbose_name, display return verbose_name, display

4
sapl/templates/materia/materialegislativa_filter.html

@ -1,6 +1,6 @@
{% extends "crud/detail.html" %} {% extends "crud/detail.html" %}
{% load i18n %} {% load i18n %}
{% load crispy_forms_tags %} {% load crispy_forms_tags common_tags%}
{% block actions %} {% block actions %}
@ -48,7 +48,7 @@
<td> <td>
<strong><a href="{% url 'sapl.materia:materialegislativa_detail' m.id %}">{{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}}</strong></a> <strong><a href="{% url 'sapl.materia:materialegislativa_detail' m.id %}">{{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}}</strong></a>
</br> </br>
<strong>Ementa:</strong>&nbsp;{{ m.ementa|safe }} <strong>Ementa:</strong>&nbsp;{{ m.ementa|dont_break_out }}
</br> </br>
{% if m.data_apresentacao %} {% if m.data_apresentacao %}
<strong>Apresentação: </strong>{{ 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> <fieldset>
<legend>Matérias do Expediente</legend> <legend>Matérias do Expediente</legend>
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
@ -33,7 +35,10 @@
<b>Processo:</b> {{ m.numero_processo }} <b>Processo:</b> {{ m.numero_processo }}
{% endif %} {% endif %}
</td> </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> <td><b>{{m.resultado}}</b><br/>{{m.resultado_observacao}}</td>
</tr> </tr>
{% endfor %} {% endfor %}

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

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

37
sapl/utils.py

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