diff --git a/requirements/requirements.txt b/requirements/requirements.txt index c5a1f6fd9..65d3e3f87 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -31,6 +31,7 @@ more-itertools==8.2.0 pysolr==3.6.0 PyPDF4==1.27.0 pyoai==2.5.0 +Unidecode==1.1.1 git+https://github.com/interlegis/trml2pdf git+https://github.com/interlegis/django-admin-bootstrapped diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 65d227894..b8a1ed246 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 @@ -2913,3 +2913,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 b94ea78ff..fe0c45c39 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -1116,3 +1116,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 05733599c..4c6c5166b 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -27,7 +27,8 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, proposicao_texto, recuperar_materia, ExcluirTramitacaoEmLoteView, RetornarProposicao, MateriaPesquisaSimplesView, - DespachoInicialMultiCreateView, get_zip_docacessorios, get_pdf_docacessorios) + DespachoInicialMultiCreateView, get_zip_docacessorios, + get_pdf_docacessorios, configEtiquetaMateriaLegislativaCrud) from sapl.norma.views import NormaPesquisaSimplesView from sapl.protocoloadm.views import ( FichaPesquisaAdmView, FichaSelecionaAdmView) @@ -172,6 +173,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 773ca0eaf..ded3dc6ea 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 @@ -72,7 +74,7 @@ from .models import (AcompanhamentoMateria, Anexada, AssuntoMateria, Autoria, De DocumentoAcessorio, MateriaAssunto, MateriaLegislativa, Numeracao, Orgao, Origem, Proposicao, RegimeTramitacao, Relatoria, StatusTramitacao, TipoDocumento, TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao, - Tramitacao, UnidadeTramitacao) + Tramitacao, UnidadeTramitacao,ConfigEtiquetaMateriaLegislativa) AssuntoMateriaCrud = CrudAux.build(AssuntoMateria, 'assunto_materia') @@ -2824,3 +2826,15 @@ def get_pdf_docacessorios(request, pk): % external_name) return response +def configEtiquetaMateriaLegislativaCrud(request): + config = ConfigEtiquetaMateriaLegislativa.objects.last() + if request.method == "POST": + form = ConfigEtiquetaMateriaLegislativaForms(request.POST, instance=config) + if form.is_valid(): + config = form.save(commit=False) + config.published_date = timezone.now() + config.save() + return redirect('materia/config_etiqueta_materia.html', {'form': form}) + else: + form = ConfigEtiquetaMateriaLegislativaForms(instance=config) + return render(request, 'materia/config_etiqueta_materia.html', {'form': form}) \ No newline at end of file diff --git a/sapl/relatorios/urls.py b/sapl/relatorios/urls.py index 05ad22671..e60a1e03e 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 35a6f6ddf..beb523bb1 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, @@ -1005,6 +1006,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, @@ -1500,3 +1503,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 e47ebe5dc..316ce8ce3 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -258,7 +258,8 @@ rules_group_geral = { (materia.Parecer, __base__, __perms_publicas__), (materia.StatusTramitacao, __base__, __perms_publicas__), (materia.UnidadeTramitacao, __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 a885a418d..142dcdf91 100644 --- a/sapl/templates/materia/layouts.yaml +++ b/sapl/templates/materia/layouts.yaml @@ -157,3 +157,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 8a83ac44f..864b8e5a6 100644 --- a/sapl/templates/menu_tabelas_auxiliares.yaml +++ b/sapl/templates/menu_tabelas_auxiliares.yaml @@ -119,6 +119,9 @@ - title: {% trans 'Assunto Matéria' %} url: sapl.materia:assuntomateria_list css_class: btn btn-link + - 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 children: 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}}

+ +
+