From 48eb0866bee1202450b148bbd02a944e82f85111 Mon Sep 17 00:00:00 2001 From: Ulysses Lara Date: Fri, 3 Jul 2020 15:53:24 -0300 Subject: [PATCH] =?UTF-8?q?3138=20gerar=20etiqueta=20com=20informa=C3=A7?= =?UTF-8?q?=C3=B5es=20da=20materia=20(#3162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix#3138 - Iniciando etiqueta de materia legislativa * Gerando pdf com codigo de barra e opção largura/altura * Anexando etiqueta em Texto Articulado * Adaptando pra ficar parecido com protocolo Fix #3138 * Colocando classe de configuração de etiqueta da materia no map rules * Ajustando importações * Melhorando a disposição dos elementos da etiqueta * Mudando fontes da etiqueta * Melhorando formato da etiqueta * Limitando campo ementa para no maximo 200 caracteres em ementa de materia legislativa * Aumenta um pouco mais o tam máx Co-authored-by: eribeiro --- requirements/requirements.txt | 1 + sapl/materia/forms.py | 9 ++- .../0068_configetiquetamaterialegislativa.py | 23 ++++++++ .../migrations/0069_auto_20200518_1519.py | 20 +++++++ sapl/materia/models.py | 8 +++ sapl/materia/urls.py | 3 +- sapl/materia/views.py | 23 ++++---- sapl/relatorios/urls.py | 4 +- sapl/relatorios/views.py | 55 ++++++++++++++++++- sapl/rules/map_rules.py | 2 + .../materia/config_etiqueta_materia.html | 19 +++++++ sapl/templates/materia/layouts.yaml | 6 ++ .../materia/materialegislativa_detail.html | 6 ++ .../materia/materialegislativa_filter.html | 2 + sapl/templates/menu_tabelas_auxiliares.yaml | 2 + .../etiqueta_materia_legislativa.html | 40 ++++++++++++++ 16 files changed, 206 insertions(+), 17 deletions(-) create mode 100644 sapl/materia/migrations/0068_configetiquetamaterialegislativa.py create mode 100644 sapl/materia/migrations/0069_auto_20200518_1519.py create mode 100644 sapl/templates/materia/config_etiqueta_materia.html create mode 100644 sapl/templates/relatorios/etiqueta_materia_legislativa.html diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 21ecac890..1c2ea59c8 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -39,6 +39,7 @@ more-itertools==8.2.0 pysolr==3.6.0 PyPDF4==1.27.0 pyoai==2.5.0 +Unidecode==1.1.1 daphne==2.2.5 channels_redis==2.3.2 diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 7dca1ef98..f27814d93 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -34,7 +34,7 @@ from sapl.materia.models import (AssuntoMateria, Autoria, MateriaAssunto, MateriaLegislativa, Orgao, RegimeTramitacao, StatusTramitacao, TipoDocumento, TipoProposicao, - UnidadeTramitacao) + UnidadeTramitacao,ConfigEtiquetaMateriaLegislativa) from sapl.norma.models import (LegislacaoCitada, NormaJuridica, TipoNormaJuridica) from sapl.parlamentares.models import Legislatura, Partido, Parlamentar @@ -2919,3 +2919,10 @@ class MateriaPesquisaSimplesForm(forms.Form): _('A Data Final não pode ser menor que a Data Inicial')) return cleaned_data + +class ConfigEtiquetaMateriaLegislativaForms(ModelForm): + class Meta: + model = ConfigEtiquetaMateriaLegislativa + fields = '__all__' + + \ No newline at end of file diff --git a/sapl/materia/migrations/0068_configetiquetamaterialegislativa.py b/sapl/materia/migrations/0068_configetiquetamaterialegislativa.py new file mode 100644 index 000000000..3dce8a3f3 --- /dev/null +++ b/sapl/materia/migrations/0068_configetiquetamaterialegislativa.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-05-18 18:14 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0067_auto_20200416_1538'), + ] + + operations = [ + migrations.CreateModel( + name='ConfigEtiquetaMateriaLegislativa', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('largura', models.FloatField(default=5)), + ('altura', models.FloatField(default=3)), + ], + ), + ] diff --git a/sapl/materia/migrations/0069_auto_20200518_1519.py b/sapl/materia/migrations/0069_auto_20200518_1519.py new file mode 100644 index 000000000..4251cb6e9 --- /dev/null +++ b/sapl/materia/migrations/0069_auto_20200518_1519.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-05-18 18:19 +from __future__ import unicode_literals + +from django.db import migrations + + +def create_first(apps, schema_editor): + db_alias = schema_editor.connection.alias + Type = apps.get_model("materia", "ConfigEtiquetaMateriaLegislativa") + Type.objects.using(db_alias).create() + +class Migration(migrations.Migration): + dependencies = [ + ('materia', '0068_configetiquetamaterialegislativa'), + ] + + operations = [ + migrations.RunPython(create_first), + ] \ No newline at end of file diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 2f45c5bd4..3e7ef4cfe 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -1129,3 +1129,11 @@ class MateriaEmTramitacao(models.Model): def __str__(self): return '{}/{}'.format(self.materia, self.tramitacao) + +class ConfigEtiquetaMateriaLegislativa(models.Model): + largura = models.FloatField(default=5) + altura = models.FloatField(default=3) + + def save(self, *args, **kwargs): + self.id = 1 + return super().save(*args, **kwargs) \ No newline at end of file diff --git a/sapl/materia/urls.py b/sapl/materia/urls.py index d59075382..b47fdc471 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -29,7 +29,7 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, MateriaPesquisaSimplesView, DespachoInicialMultiCreateView, TipoTurnoTramitacaoCrud, - get_zip_docacessorios, get_pdf_docacessorios) + get_zip_docacessorios, get_pdf_docacessorios, configEtiquetaMateriaLegislativaCrud) from sapl.norma.views import NormaPesquisaSimplesView from sapl.protocoloadm.views import ( FichaPesquisaAdmView, FichaSelecionaAdmView) @@ -178,6 +178,7 @@ urlpatterns_sistema = [ url(r'^sistema/materia/status-tramitacao/', include(StatusTramitacaoCrud.get_urls())), url(r'^sistema/materia/orgao/', include(OrgaoCrud.get_urls())), + url(r'^sistema/materia/config-etiqueta-materia-legislativas/',configEtiquetaMateriaLegislativaCrud, name="configEtiquetaMateriaLegislativaCrud"), ] urlpatterns = urlpatterns_impressos + urlpatterns_materia + \ diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 9f1873c71..fb89cfb06 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -32,6 +32,8 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic import CreateView, ListView, TemplateView, UpdateView from django.views.generic.base import RedirectView from django.views.generic.edit import FormView +from django.shortcuts import render + from django_filters.views import FilterView @@ -48,7 +50,7 @@ from sapl.materia.forms import (AnexadaForm, AutoriaForm, AutoriaMultiCreateForm ConfirmarProposicaoForm, DevolverProposicaoForm, DespachoInicialCreateForm, LegislacaoCitadaForm, MateriaPesquisaSimplesForm, OrgaoForm, ProposicaoForm, - TipoProposicaoForm, TramitacaoForm, TramitacaoUpdateForm) + TipoProposicaoForm, TramitacaoForm, TramitacaoUpdateForm,ConfigEtiquetaMateriaLegislativaForms) from sapl.norma.models import LegislacaoCitada from sapl.parlamentares.models import Legislatura from sapl.protocoloadm.models import Protocolo @@ -66,17 +68,14 @@ from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, filtra_tramitacao_destino_and_status, filtra_tramitacao_status, MateriaAssuntoForm, MateriaLegislativaFilterSet, MateriaLegislativaForm, MateriaSimplificadaForm, PrimeiraTramitacaoEmLoteFilterSet, - ReceberProposicaoForm, RelatoriaForm, - TramitacaoEmLoteFilterSet, UnidadeTramitacaoForm, - ExcluirTramitacaoEmLote, compara_tramitacoes_mat, - TramitacaoEmLoteForm) -from .models import (AcompanhamentoMateria, Anexada, AssuntoMateria, Autoria, - DespachoInicial, DocumentoAcessorio, MateriaAssunto, - MateriaLegislativa, Numeracao, Orgao, Origem, Proposicao, - RegimeTramitacao, Relatoria, StatusTramitacao, - TipoDocumento, TipoFimRelatoria, TipoMateriaLegislativa, - TipoProposicao, Tramitacao, UnidadeTramitacao, - TipoTurnoTramitacao) + ReceberProposicaoForm, RelatoriaForm, TramitacaoEmLoteFilterSet, + TramitacaoEmLoteForm, UnidadeTramitacaoForm) +from .models import (AcompanhamentoMateria, Anexada, AssuntoMateria, Autoria, DespachoInicial, + DocumentoAcessorio, MateriaAssunto, MateriaLegislativa, Numeracao, Orgao, + Origem, Proposicao, RegimeTramitacao, Relatoria, StatusTramitacao, + TipoDocumento, TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao, + Tramitacao, UnidadeTramitacao, TipoTurnoTramitacao, ConfigEtiquetaMateriaLegislativa) + AssuntoMateriaCrud = CrudAux.build(AssuntoMateria, 'assunto_materia') diff --git a/sapl/relatorios/urls.py b/sapl/relatorios/urls.py index 5a863fbc9..420fc8519 100644 --- a/sapl/relatorios/urls.py +++ b/sapl/relatorios/urls.py @@ -6,7 +6,7 @@ from .views import (relatorio_capa_processo, relatorio_etiqueta_protocolo, relatorio_materia, relatorio_ordem_dia, relatorio_pauta_sessao, relatorio_protocolo, relatorio_sessao_plenaria, - resumo_ata_pdf, relatorio_sessao_plenaria_pdf) + resumo_ata_pdf, relatorio_sessao_plenaria_pdf, etiqueta_materia_legislativa) app_name = AppConfig.name @@ -33,4 +33,6 @@ urlpatterns = [ resumo_ata_pdf, name='resumo_ata_pdf'), url(r'^relatorios/(?P\d+)/sessao-plenaria-pdf$', relatorio_sessao_plenaria_pdf, name='relatorio_sessao_plenaria_pdf'), + url(r'^relatorios/(?P\d+)/etiqueta-materia-legislativa$', + etiqueta_materia_legislativa, name='etiqueta_materia_legislativa'), ] diff --git a/sapl/relatorios/views.py b/sapl/relatorios/views.py index d7e1085a8..7112e46df 100755 --- a/sapl/relatorios/views.py +++ b/sapl/relatorios/views.py @@ -3,6 +3,7 @@ import html import logging import re import tempfile +import unidecode from django.core.exceptions import ObjectDoesNotExist from django.http import Http404, HttpResponse @@ -15,7 +16,7 @@ from sapl.settings import MEDIA_URL from sapl.base.models import Autor, CasaLegislativa from sapl.comissoes.models import Comissao from sapl.materia.models import (Autoria, MateriaLegislativa, Numeracao, - Tramitacao, UnidadeTramitacao) + Tramitacao, UnidadeTramitacao, ConfigEtiquetaMateriaLegislativa) from sapl.parlamentares.models import CargoMesa, Filiacao, Parlamentar from sapl.protocoloadm.models import (DocumentoAdministrativo, Protocolo, TramitacaoAdministrativo) @@ -26,7 +27,7 @@ from sapl.sessao.models import (ExpedienteMateria, ExpedienteSessao, SessaoPlenariaPresenca, OcorrenciaSessao, RegistroVotacao, VotoParlamentar, OradorOrdemDia, TipoExpediente, ResumoOrdenacao) from sapl.settings import STATIC_ROOT -from sapl.utils import LISTA_DE_UFS, TrocaTag, filiacao_data +from sapl.utils import LISTA_DE_UFS, TrocaTag, filiacao_data, create_barcode from sapl.sessao.views import (get_identificacao_basica, get_mesa_diretora, get_presenca_sessao, get_expedientes, @@ -1007,6 +1008,8 @@ def relatorio_etiqueta_protocolo(request, nro, ano): protocolo = Protocolo.objects.filter(numero=nro, ano=ano) + m = MateriaLegislativa.objects.filter(numero_protocolo=nro,ano=ano) + protocolo_data = get_etiqueta_protocolos(protocolo) pdf = pdf_etiqueta_protocolo_gerar.principal(imagem, @@ -1503,3 +1506,51 @@ def relatorio_sessao_plenaria_pdf(request, pk): response.write(pdf_file) return response + + +def gera_etiqueta_ml(materia_legislativa, base_url): + confg = ConfigEtiquetaMateriaLegislativa.objects.first() + + ml_info = unidecode.unidecode("{}/{}-{}".format(materia_legislativa.numero, + materia_legislativa.ano, + materia_legislativa.tipo.sigla)) + base64_data = create_barcode(ml_info, 100, 500) + barcode = 'data:image/png;base64,{0}'.format(base64_data) + + max_ementa_size = 240 + ementa = materia_legislativa.ementa + ementa = ementa if len(ementa) < max_ementa_size else ementa[:max_ementa_size]+"..." + + context = { + 'numero': materia_legislativa.numero, + 'ano': materia_legislativa.ano, + 'tipo': materia_legislativa.tipo, + 'data_apresentacao':materia_legislativa.data_apresentacao, + 'autores': materia_legislativa.autores.all(), + 'ementa':ementa, + 'largura': confg.largura, + 'altura':confg.largura, + 'barcode': barcode + } + + main_template = render_to_string('relatorios/etiqueta_materia_legislativa.html', context) + + html = HTML(base_url=base_url, string=main_template) + main_doc = html.render(stylesheets=[CSS(string="@page {{size: {}cm {}cm;}}".format(confg.largura,confg.altura))]) + + pdf_file = main_doc.write_pdf() + return pdf_file + + +def etiqueta_materia_legislativa(request, pk): + base_url = request.build_absolute_uri() + materia_legislativa = MateriaLegislativa.objects.get(pk=pk) + + pdf_file = gera_etiqueta_ml(materia_legislativa, base_url) + + response = HttpResponse(content_type='application/pdf;') + response['Content-Disposition'] = 'inline; filename=etiqueta.pdf' + response['Content-Transfer-Encoding'] = 'binary' + response.write(pdf_file) + + return response \ No newline at end of file diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index f9a592594..71fe66af4 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -267,6 +267,8 @@ rules_group_geral = { (materia.UnidadeTramitacao, __base__, __perms_publicas__), (materia.TipoTurnoTramitacao, __base__, __perms_publicas__), + (materia.ConfigEtiquetaMateriaLegislativa, __base__, set()), + (norma.AssuntoNorma, __base__, __perms_publicas__), (norma.TipoNormaJuridica, __base__, __perms_publicas__), diff --git a/sapl/templates/materia/config_etiqueta_materia.html b/sapl/templates/materia/config_etiqueta_materia.html new file mode 100644 index 000000000..cea6716c6 --- /dev/null +++ b/sapl/templates/materia/config_etiqueta_materia.html @@ -0,0 +1,19 @@ +{% extends "crud/form.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block base_content %} +

Configuração Etiqueta Materia Legislativa

+
+ {% csrf_token %} + {{ form|crispy }} +
+
+
+ Cancelar + +
+
+
+
+{% endblock base_content %} diff --git a/sapl/templates/materia/layouts.yaml b/sapl/templates/materia/layouts.yaml index 24e3b9b29..367458244 100644 --- a/sapl/templates/materia/layouts.yaml +++ b/sapl/templates/materia/layouts.yaml @@ -161,3 +161,9 @@ MateriaLegislativaDetail: - ementa - indexacao - observacao + +ConfigEtiquetaMateriaLegislativa: + {% trans 'Configurações de Etiqueta' %}: + - largura + - altura + - mostrar_em_arquivo \ No newline at end of file diff --git a/sapl/templates/materia/materialegislativa_detail.html b/sapl/templates/materia/materialegislativa_detail.html index 10749b765..2d46b3312 100644 --- a/sapl/templates/materia/materialegislativa_detail.html +++ b/sapl/templates/materia/materialegislativa_detail.html @@ -10,6 +10,12 @@ {% endif %} {% endblock sub_actions %} +{% block editions %} + {{ block.super }} + {% trans 'Etiqueta' %} +{% endblock editions %} + + {% block detail_content %} {{ block.super }} {% if object.registrovotacao_set.exists %} diff --git a/sapl/templates/materia/materialegislativa_filter.html b/sapl/templates/materia/materialegislativa_filter.html index 5cf56d17d..9e91c29b8 100644 --- a/sapl/templates/materia/materialegislativa_filter.html +++ b/sapl/templates/materia/materialegislativa_filter.html @@ -1,6 +1,7 @@ {% extends "crud/detail.html" %} {% load i18n %} {% load crispy_forms_tags common_tags%} +{% load webpack_static from webpack_loader %} {% block actions %} @@ -47,6 +48,7 @@ {{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}} + Etiqueta Individual
Ementa: {{ m.ementa|dont_break_out }}
diff --git a/sapl/templates/menu_tabelas_auxiliares.yaml b/sapl/templates/menu_tabelas_auxiliares.yaml index 36560e651..7030463f6 100644 --- a/sapl/templates/menu_tabelas_auxiliares.yaml +++ b/sapl/templates/menu_tabelas_auxiliares.yaml @@ -124,6 +124,8 @@ css_class: btn btn-link - title: {% trans 'Tipo de Turnos de Tramitação' %} url: sapl.materia:tipoturnotramitacao_list + - title: {% trans 'Configuração Etiqueta Materia Legislativa' %} + url: sapl.materia:configEtiquetaMateriaLegislativaCrud css_class: btn btn-link - title: {% trans 'Módulo Normas Jurídicas' %} css_class: head_title diff --git a/sapl/templates/relatorios/etiqueta_materia_legislativa.html b/sapl/templates/relatorios/etiqueta_materia_legislativa.html new file mode 100644 index 000000000..365d02bfb --- /dev/null +++ b/sapl/templates/relatorios/etiqueta_materia_legislativa.html @@ -0,0 +1,40 @@ + +{% load i18n %} +{% load crispy_forms_tags %} +{% load common_tags %} +{% load static %} + + + + + + + +
+

Materia Legislativa - {{numero}}/{{ano}}

+

Tipo: {{tipo.sigla}} - {{tipo.descricao}}

+

Data: {{data_apresentacao}}

+

Ementa: {{ementa}}

+ +
+