Browse Source

Fix # 2488

Co-authored-by: ulyssesBML <ulysses3353@gmail.com>
sobe alterações

Iniciando relatorio com weasyprint

Atualizando informaçoes do relatorio de reunião

Arrumando logo e topicos incompletos

Refatorando codigo para gerar relatorio

Adicionando butão para novo estilo de relatorio

Arrumando erros relatados noPR

Arrumando margens das tabelas e dos headers
pull/2513/head
Victor Fabre 7 years ago
committed by ulysses
parent
commit
196915d337
  1. 5
      sapl/relatorios/urls.py
  2. 104
      sapl/relatorios/views.py
  3. 30
      sapl/static/css/header-relatorio.css
  4. 55
      sapl/static/css/relatorio.css
  5. 39
      sapl/templates/relatorios/header.html
  6. 182
      sapl/templates/relatorios/relatorio_sessao_plenaria.html
  7. 4
      sapl/templates/sessao/resumo.html

5
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,
relatorio_sessao_plenaria_pdf)
app_name = AppConfig.name
@ -28,4 +29,6 @@ urlpatterns = [
relatorio_etiqueta_protocolo, name='relatorio_etiqueta_protocolo'),
url(r'^relatorios/pauta-sessao/(?P<pk>\d+)/$',
relatorio_pauta_sessao, name='relatorio_pauta_sessao'),
url(r'^relatorios/(?P<pk>\d+)/sessao-plenaria-pdf$',
relatorio_sessao_plenaria_pdf, name='relatorio_sessao_plenaria_pdf'),
]

104
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,
@ -21,7 +23,7 @@ from sapl.sessao.models import (ExpedienteMateria, ExpedienteSessao,
OrdemDia, PresencaOrdemDia, SessaoPlenaria,
SessaoPlenariaPresenca, OcorrenciaSessao,
RegistroVotacao, VotoParlamentar)
from sapl.settings import STATIC_ROOT
from sapl.settings import STATIC_ROOT, STATIC_URL
from sapl.utils import LISTA_DE_UFS, TrocaTag, filiacao_data
from .templates import (pdf_capa_processo_gerar,
@ -30,6 +32,9 @@ from .templates import (pdf_capa_processo_gerar,
pdf_ordem_dia_gerar, pdf_pauta_sessao_gerar,
pdf_protocolo_gerar, pdf_sessao_plenaria_gerar)
from weasyprint import HTML, CSS
from sapl.settings import MEDIA_URL
def get_kwargs_params(request, fields):
kwargs = {}
@ -904,6 +909,103 @@ def relatorio_sessao_plenaria(request, pk):
return response
def relatorio_sessao_plenaria_pdf(request, pk):
base_url=request.build_absolute_uri()
logger = logging.getLogger(__name__)
username = request.user.username
casa = CasaLegislativa.objects.first()
if not casa:
raise Http404
rodape = get_rodape(casa)
rodape = ' '.join(rodape)
try:
logger.debug("user=" + username +
". Tentando obter SessaoPlenaria com id={}.".format(pk))
sessao = SessaoPlenaria.objects.get(id=pk)
except ObjectDoesNotExist as e:
logger.error("user=" + username +
". Essa SessaoPlenaria não existe (pk={}). ".format(pk) + str(e))
raise Http404('Essa página não existe')
(inf_basicas_dic,
lst_mesa,
lst_presenca_sessao,
lst_ausencia_sessao,
lst_expedientes,
lst_expediente_materia,
lst_expediente_materia_vot_nom,
lst_oradores_expediente,
lst_presenca_ordem_dia,
lst_votacao,
lst_votacao_vot_nom,
lst_oradores,
lst_ocorrencias) = get_sessao_plenaria(sessao, casa)
html_template = render_to_string('relatorios/relatorio_sessao_plenaria.html',
{
"inf_basicas_dic":inf_basicas_dic,
"lst_mesa":lst_mesa,
"lst_presenca_sessao":lst_presenca_sessao,
"lst_ausencia_sessao":lst_ausencia_sessao,
"lst_expedientes":lst_expedientes,
"lst_expediente_materia":lst_expediente_materia,
"lst_oradores_expediente":lst_oradores_expediente,
"lst_presenca_ordem_dia":lst_presenca_ordem_dia,
"lst_votacao":lst_votacao,
"lst_oradores":lst_oradores,
"lst_ocorrencias":lst_ocorrencias,
"rodape":rodape,
"data": dt.today().strftime('%d/%m/%Y')
})
html_header = render_to_string('relatorios/header.html',{"info":inf_basicas_dic,
"MEDIA_URL": MEDIA_URL,
"logotipo": casa.logotipo})
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
def make_pdf(base_url, main_template, header_template):
# Main template
html = HTML(base_url=base_url, string=main_template)
main_doc = html.render()
exists_links = False
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='div {position: fixed; top: 0cm; left: 0cm;}')])
header_page = header.pages[0]
exists_links = exists_links or header_page.links
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()
if exists_links:
page.links.extend(header_page.links)
pdf_file = main_doc.write_pdf()
return pdf_file
def get_protocolos(prots):
protocolos = []

30
sapl/static/css/header-relatorio.css

@ -0,0 +1,30 @@
html body p {
border-top: 1px solid black;
text-align: center;
font-size: 11pt;
padding: 5px;
}
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: 50px;
}
h3 {
font-size: 12pt;
color: #6e6e6e;
}

55
sapl/static/css/relatorio.css

@ -0,0 +1,55 @@
@page{
margin-top: 8cm;
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;
}
table {
max-width: 520px;
}
table.grayTable {
border: 1px solid #6e6e6e;
width: 100%;
text-align: left;
border-collapse: collapse;
}
table.grayTable td, table.grayTable th {
border: 1px solid #000000;
}
table.grayTable tbody td {
font-size: 10px;
max-width: 80px;
overflow-wrap: break-word;
word-wrap: break-word;
text-align: justify;
}
table.grayTable tr:nth-child(even) {
background: #dddddd;
}
table.grayTable thead {
background: #BBBBBB;
border-bottom: 2px solid #000000;
}
table.grayTable thead th {
font-size:10px;
color: rgb(0, 0, 0);
border-left: 1px solid #000000;
}
table.grayTable thead th:first-child {
border-left: none;
}

39
sapl/templates/relatorios/header.html

@ -0,0 +1,39 @@
{% load i18n staticfiles menus %}
{% load common_tags %}
{% load render_bundle from webpack_loader %}
{% load webpack_static from webpack_loader %}
{% load static %}
<!DOCTYPE html>
<meta charset="utf-8">
</meta>
<html lang="pt-br">
<head>
<link rel="stylesheet" href="{% static '/css/header-relatorio.css' %}">
</head>
<body>
<section id="informations">
<dl>
<dt class="image-header">
<img src="{% if logotipo %}{{ MEDIA_URL }}{{ logotipo }}{% else %}{% webpack_static 'img/logo.png' %}{% endif %}"
alt="Logo">
</dt>
<dd class="title">
<ul>
<li><h1>{{ info.nom_camara }}</h1></li>
<li><h3>Sistema de Apoio ao Processo Legislativo</h3></li>
</ul>
</dd>
</dl>
</section>
<p>Resumo da {{ info.num_sessao_plen }} Reunião {{nom_sessao}} da {{ info.num_sessao_leg}} Sessão Legislativa da
{{info.num_legislatura}} Legislatura</p>
</body>
</html>

182
sapl/templates/relatorios/relatorio_sessao_plenaria.html

@ -0,0 +1,182 @@
{% load static %}
<!DOCTYPE html>
<meta charset="utf-8">
</meta>
<html lang="pt-br">
<head>
<style>
@page{
@bottom-right {
content: "Página" counter(page);
height: 3cm;
font-size: 8pt;
}
@bottom-center {
border-top: 1px solid black;
font-size: 8pt;
height: 1cm;
content: "{{rodape}}";
font-style:italic;
}
@bottom-left {
content: "{{data}}";
height: 3cm;
font-size: 8pt;
}
@top-center {
content: string(title);
}
header {
width: 0;
height: 0;
visibility: hidden;
string-set: title content();
}
}
</style>
<link rel="stylesheet" href="{% static '/css/relatorio.css' %}">
</head>
<body>
<div style="margin-bottom: 3cm">
<h2 class="gray-title">Informações Básicas</h2>
<p><b>Tipo da Sessão:</b> {{inf_basicas_dic.nom_sessao}}</p>
<p><b>Abertura:</b> {{inf_basicas_dic.dat_inicio_sessao}} - {{inf_basicas_dic.hr_inicio_sessao}}</p>
<p><b>Encerramento:</b> {{inf_basicas_dic.dat_fim_sessao}} - {{inf_basicas_dic.hr_fim_sessao}}</p>
<h2 class="gray-title">Mesa Diretora</h2>
{% for membro in lst_mesa%}
<p><b>{{membro.des_cargo}}:</b> {{membro.nom_parlamentar}}/{{membro.sgl_partido}}</p>
{% endfor%}
<h2 class="gray-title">Lista de Presença da Sessão</h2>
{% for membro in lst_presenca_sessao%}
<p>{{membro.nom_parlamentar}}/{{membro.sgl_partido}}</p>
{% endfor%}
<h2 class="gray-title">Justificativas de Ausência da Sessão</h2>
<table class="grayTable">
<thead>
<tr>
<th>Parlamentar</th>
<th>Justificativa</th>
<th>Ausente em</th>
</tr>
</thead>
<tbody>
{% for ausencia in lst_ausencia_sessao%}
<tr>
<td>{{ausencia.parlamentar}}</td>
<td>{{ausencia.justificativa}}</td>
<td>{{ausencia.tipo}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h2 class="gray-title">Expedientes</h2>
{% for expediente in lst_expedientes%}
<h3>{{expediente.nom_expediente}}</h3>
<p style="margin-bottom: 1cm">{{expediente.txt_expediente|safe}}</p>
{% endfor%}
<h2 class="gray-title">Matérias do Expediente</h2>
<table class="grayTable">
<thead>
<tr>
<th>Matéria</th>
<th>Ementa</th>
<th>Resultado da Votação</th>
</tr>
</thead>
<tbody>
{% for materia in lst_expediente_materia%}
<tr>
<td style="width:300px">
<dl>
<dt><b>{{materia.num_ordem}} -</b> {{materia.id_materia}}</dt>
<dt><b>Turno:</b> {{materia.des_turno}}</dt>
<dt><b>{{materia.num_autores}}: </b>{{materia.nom_autor}}</dt>
</dl>
</td>
<td><div style="margin:10px">{{materia.txt_ementa}}</div></td>
<td style="width:10px"><b>{{materia.nom_resultado}}</b></td>
</tr>
{% endfor %}
</tbody>
</table>
<h2 class="gray-title">Oradores do Expediente</h2>
{% for orador in lst_oradores_expediente%}
<tr>
<p> <b>{{orador.num_ordem}}</b> - {{orador.nom_parlamentar}}/{{orador.sgl_partido}}</p>
</tr>
{% endfor %}
<h2 class="gray-title">Lista de Presença da Ordem do Dia</h2>
{% for orador in lst_presenca_ordem_dia%}
<tr>
<p>{{orador.nom_parlamentar}}/{{orador.sgl_partido}}</p>
</tr>
{% endfor %}
<h2 class="gray-title">Matérias da Ordem do Dia</h2>
<table class="grayTable" style="height: 145px;" width="443">
<thead>
<tr>
<th>Matéria</th>
<th>Ementa</th>
<th>Resultado da Votação</th>
</tr>
</thead>
<tbody>
{% for materia in lst_votacao%}
<tr>
<td style="width:300px">
<dl>
<dt><b>{{materia.num_ordem}} -</b> {{materia.id_materia}}</dt>
<dt><b>Turno:</b> {{materia.des_turno}}</dt>
<dt><b>{{materia.num_autores}}: </b>{{materia.nom_autor}}</dt>
</dl>
</td>
<td><div style="margin:10px">{{materia.txt_ementa}}</div></td>
<td style="width:30px"><b>{{materia.nom_resultado}}</b></td>
</tr>
{% endfor %}
</tbody>
</table>
<div>
<h2 class="gray-title">Oradores das Explicações Pessoais</h2>
{% for orador in lst_oradores%}
<tr>
<p style="page-break-after: avoid;">{{orador.num_ordem}} - {{orador.nom_parlamentar}}/{{orador.sgl_partido}}</p>
</tr>
{% endfor %}
</div>
<h2 class="gray-title">Ocorrências da Sessão</h2>
{% for ocorrencia in lst_ocorrencias%}
<p>{{ocorrencia}}</p>
{% endfor %}
</div>
</body>
</html>

4
sapl/templates/sessao/resumo.html

@ -16,6 +16,10 @@
<a href="{% url 'sapl.relatorios:relatorio_sessao_plenaria' sessaoplenaria.pk %}">
Impressão PDF
</a>
<br>
<a href="{% url 'sapl.relatorios:relatorio_sessao_plenaria_pdf' sessaoplenaria.pk %}">
Impressão PDF (Novo)
</a>
</strong>
</p>
</div>

Loading…
Cancel
Save