diff --git a/sapl/relatorios/urls.py b/sapl/relatorios/urls.py index e31f5dcab..911763a09 100644 --- a/sapl/relatorios/urls.py +++ b/sapl/relatorios/urls.py @@ -5,7 +5,8 @@ from .views import (relatorio_capa_processo, relatorio_documento_administrativo, relatorio_espelho, relatorio_etiqueta_protocolo, relatorio_materia, relatorio_ordem_dia, relatorio_pauta_sessao, - relatorio_protocolo, relatorio_sessao_plenaria) + relatorio_protocolo, relatorio_sessao_plenaria, + texto_articulado_pdf) app_name = AppConfig.name @@ -28,4 +29,6 @@ urlpatterns = [ relatorio_etiqueta_protocolo, name='relatorio_etiqueta_protocolo'), url(r'^relatorios/pauta-sessao/(?P\d+)/$', relatorio_pauta_sessao, name='relatorio_pauta_sessao'), + url(r'^relatorios/texto_articulado/(?P\d+)/$', + texto_articulado_pdf, name='texto_articulado'), ] diff --git a/sapl/relatorios/views.py b/sapl/relatorios/views.py index 53331eadd..7d3a0c5c2 100755 --- a/sapl/relatorios/views.py +++ b/sapl/relatorios/views.py @@ -7,7 +7,9 @@ from django.core.exceptions import ObjectDoesNotExist from django.http import Http404, HttpResponse from django.utils import timezone from django.utils.translation import ugettext_lazy as _ +from django.template.loader import render_to_string +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, @@ -30,6 +32,10 @@ from .templates import (pdf_capa_processo_gerar, pdf_ordem_dia_gerar, pdf_pauta_sessao_gerar, pdf_protocolo_gerar, pdf_sessao_plenaria_gerar) +from sapl.compilacao.models import TextoArticulado + +from weasyprint import HTML, CSS + def get_kwargs_params(request, fields): kwargs = {} @@ -1199,3 +1205,55 @@ def get_pauta_sessao(sessao, casa): return (lst_expediente_materia, lst_votacao, inf_basicas_dic) + +def make_pdf(base_url,main_template,header_template,main_css='',header_css=''): + html = HTML(base_url=base_url, string=main_template) + main_doc = html.render(stylesheets=[]) + + def get_page_body(boxes): + for box in boxes: + if box.element_tag == 'body': + return box + return get_page_body(box.all_children()) + + # Template of header + html = HTML(base_url=base_url,string=header_template) + header = html.render(stylesheets=[CSS(string='@page {size:A4; margin:1cm;}')]) + + header_page = header.pages[0] + header_body = get_page_body(header_page._page_box.all_children()) + header_body = header_body.copy_with_children(header_body.all_children()) + + for page in main_doc.pages: + page_body = get_page_body(page._page_box.all_children()) + page_body.children += header_body.all_children() + + pdf_file = main_doc.write_pdf() + + return pdf_file + + +def texto_articulado_pdf(request,pk): + texto_articulado = TextoArticulado.objects.get(pk=pk) + base_url = request.build_absolute_uri() + casa = CasaLegislativa.objects.first() + rodape = ' '.join(get_rodape(casa)) + + context = { + 'object': texto_articulado, + 'rodape': rodape, + 'data': dt.today().strftime('%d/%m/%Y') + } + html_template = render_to_string('relatorios/relatorio_texto.html',context) + + header_context = {"casa":casa, 'logotipo':casa.logotipo, 'MEDIA_URL': MEDIA_URL} + html_header = render_to_string('relatorios/header.html', header_context) + + pdf_file = make_pdf(base_url=base_url,main_template=html_template,header_template=html_header) + + response = HttpResponse(content_type='application/pdf;') + response['Content-Disposition'] = 'inline; filename=relatorio.pdf' + response['Content-Transfer-Encoding'] = 'binary' + response.write(pdf_file) + + return response \ No newline at end of file diff --git a/sapl/static/sapl/css/header-relatorio.css b/sapl/static/sapl/css/header-relatorio.css new file mode 100644 index 000000000..ea24567c8 --- /dev/null +++ b/sapl/static/sapl/css/header-relatorio.css @@ -0,0 +1,46 @@ +html body p { + border-top: 1px solid black; + text-align: center; + font-size: 11pt; + padding: 5px; + margin-top: -15px; +} +html body section { + box-sizing: border-box; +} +html body section dl { + display: flex; + flex-wrap: wrap; + rows: 2; + columns: 2; +} +html body section dt{ + width: 50px; +} +html body section dd { + max-width:550px; + text-align: center; +} +html body section dd ul li { + list-style-type: none; + margin-left: 90px; + margin-bottom: -15px; + +} +h2 { + font-size: 14pt; +} +h3 { + font-size: 10pt; + color: #6e6e6e; +} +ul { + padding: 0; + list-style: none; + margin-top:10px; +} + +html body section dt img { + max-width:80px; + margin-left: 20px; +} \ No newline at end of file diff --git a/sapl/static/sapl/css/relatorio.css b/sapl/static/sapl/css/relatorio.css new file mode 100644 index 000000000..c3f2ec21f --- /dev/null +++ b/sapl/static/sapl/css/relatorio.css @@ -0,0 +1,56 @@ +@page{ + margin-top: 4.5cm; + size: A4 portrait; +} + +h2.gray-title{ + color: gray; + font-size: 14pt; + break-after: avoid-page; + page-break-after: avoid; +} + +h3 { + font-size: 10pt; + break-after: avoid-page; + page-break-after: avoid; +} + +p { + font-size: 10pt; + text-align: justify; + text-justify: inter-word; +} + +fieldset { + border: 0; +} + +html body section { + box-sizing: border-box; +} + +html body section dl { + display: flex; + flex-wrap: wrap; + columns: 5; +} + +html body section dt{ + width: 50px; +} + +html body section dd { + text-align: center; +} + +html body section dd ul li { + list-style-type: none; + margin-left: 50px; +} + +fieldset { + page-break-after: avoid; + margin:5px; + padding:0px; +} \ No newline at end of file diff --git a/sapl/templates/compilacao/textoarticulado_detail.html b/sapl/templates/compilacao/textoarticulado_detail.html index 9560a95f7..135f17bb1 100644 --- a/sapl/templates/compilacao/textoarticulado_detail.html +++ b/sapl/templates/compilacao/textoarticulado_detail.html @@ -21,7 +21,7 @@ {% if perms.compilacao.lock_unlock_textoarticulado and not object.editable_only_by_owners%} {% if object.editing_locked %}{% trans 'Desbloquear Edição' %}{%else%}{% trans 'Publicar Texto' %}{% endif %} {% endif %} - + Imprimir Texto {% endblock actions %} diff --git a/sapl/templates/relatorios/header.html b/sapl/templates/relatorios/header.html new file mode 100644 index 000000000..f18a0aa86 --- /dev/null +++ b/sapl/templates/relatorios/header.html @@ -0,0 +1,31 @@ +{% load common_tags %} +{% load render_bundle from webpack_loader %} +{% load webpack_static from webpack_loader %} +{% load static %} + + + + + + + + + + +
+
+
+ +
+
+
    +
  • {{casa}}

  • +
  • Sistema de Apoio ao Processo Legislativo

  • +
+
+
+
+

+ + + \ No newline at end of file diff --git a/sapl/templates/relatorios/relatorio_texto.html b/sapl/templates/relatorios/relatorio_texto.html new file mode 100644 index 000000000..664e7a6ae --- /dev/null +++ b/sapl/templates/relatorios/relatorio_texto.html @@ -0,0 +1,52 @@ + +{% load common_tags %} +{% load static %} + + + + + + +

Texto Articulado: {{object}}

+ +

Identificação Básica

+

Tipo de Texto Articulado: {{object.tipo_ta}}

+

Tipo da Norma Jurídica: {{object.content_object.tipo}}

+

Número: {{object.numero}}

+

Ano: {{object.ano}}

+

Data: {{object.data}}

+ +

Ementa

+

{{object.ementa}}

+ \ No newline at end of file