From 3c05464414f9cef40720cd6cdea8998ae3b437b3 Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Tue, 26 Feb 2019 23:16:35 -0300 Subject: [PATCH] =?UTF-8?q?Prop=C3=B5e=20solu=C3=A7=C3=A3o=20para=20TextFi?= =?UTF-8?q?elds=20com=20sequ=C3=AAncias=20longas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/templatetags/common_tags.py | 13 +++++- sapl/crispy_layout_mixin.py | 1 + .../materia/materialegislativa_filter.html | 4 +- .../blocos_resumo/materias_expediente.html | 7 +++- .../blocos_resumo/materias_ordem_dia.html | 4 +- sapl/utils.py | 41 +++++++++++++++---- sapl/webpack-stats.json | 2 +- 7 files changed, 57 insertions(+), 15 deletions(-) diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index 3c72b1654..26fd54f4d 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/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 = '
{}
'.format(value) + _safe = mark_safe(_safe) + return _safe + diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index 200f24db1..b6af79427 100644 --- a/sapl/crispy_layout_mixin.py +++ b/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', '
') + display = '
{}
'.format(display) else: display = str(value) return verbose_name, display diff --git a/sapl/templates/materia/materialegislativa_filter.html b/sapl/templates/materia/materialegislativa_filter.html index 577cd3769..5cf56d17d 100644 --- a/sapl/templates/materia/materialegislativa_filter.html +++ b/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 @@ {{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}}
- Ementa: {{ m.ementa|safe }} + Ementa: {{ m.ementa|dont_break_out }}
{% if m.data_apresentacao %} Apresentação: {{ m.data_apresentacao }} diff --git a/sapl/templates/sessao/blocos_resumo/materias_expediente.html b/sapl/templates/sessao/blocos_resumo/materias_expediente.html index 48dcf9c14..f32216df1 100644 --- a/sapl/templates/sessao/blocos_resumo/materias_expediente.html +++ b/sapl/templates/sessao/blocos_resumo/materias_expediente.html @@ -1,3 +1,5 @@ + +{% load common_tags %}
Matérias do Expediente @@ -33,7 +35,10 @@ Processo: {{ m.numero_processo }} {% endif %} - + {% endfor %} diff --git a/sapl/templates/sessao/blocos_resumo/materias_ordem_dia.html b/sapl/templates/sessao/blocos_resumo/materias_ordem_dia.html index fc8807534..e635ee959 100644 --- a/sapl/templates/sessao/blocos_resumo/materias_ordem_dia.html +++ b/sapl/templates/sessao/blocos_resumo/materias_ordem_dia.html @@ -1,3 +1,5 @@ + +{% load common_tags %}
Matérias da Ordem do Dia
{{m.ementa|safe}}
{{m.observacao}}
+ {{m.ementa|dont_break_out}}
+ {{m.observacao|dont_break_out}} +
{{m.resultado}}
{{m.resultado_observacao}}
@@ -33,7 +35,7 @@ Processo: {{ m.numero_processo }} {% endif %} - + {% endfor %} diff --git a/sapl/utils.py b/sapl/utils.py index 9c7350c63..365eb30f5 100644 --- a/sapl/utils.py +++ b/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 '
' + '
'.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 = ''' ''' - autor_modal = '''
{{m.ementa|safe}}
{{m.ementa_observacao}}
{{m.ementa|dont_break_out}}
{{m.observacao|dont_break_out}}
{{m.resultado}}
{{m.resultado_observacao}}