Browse Source

Usar pisa para mais alguns relatórios

pull/11/head
Sesostris Vieira 6 years ago
parent
commit
6bcb0ae5a9
  1. 116
      sigi/apps/casas/reports.py
  2. 132
      sigi/apps/casas/templates/casas/report_pdf.html
  3. 24
      sigi/apps/casas/views.py

116
sigi/apps/casas/reports.py

@ -177,119 +177,3 @@ class CasasLegislativasLabelsSemPresidente(CasasLegislativasLabels):
display_inline=True, display_inline=True,
default_style={'fontName': 'Helvetica', 'fontSize': self.tamanho_fonte}) default_style={'fontName': 'Helvetica', 'fontSize': self.tamanho_fonte})
class CasasLegislativasReport(ReportDefault):
title = _(u'Relatório de Casas Legislativas')
height = 80 * cm
page_size = landscape(A4)
class band_page_header(ReportDefault.band_page_header):
label_top = ReportDefault.band_page_header.label_top
label_left = [0.3, 1, 5.5, 11, 17, 22]
elements = list(ReportDefault.band_page_header.elements)
elements = [
Image(filename=static('img/logo-interlegis.jpg'),
left=23.5 * cm, right=1 * cm, top=0.1 * cm, bottom=1 * cm,
width=4.2 * cm, height=3 * cm,
),
Image(filename=static('img/logo-senado.png'),
left=1 * cm, right=1 * cm, top=0.1 * cm, bottom=1 * cm,
width=3 * cm, height=3 * cm,
),
Label(text=_(u"SENADO FEDERAL"), top=1 * cm, left=0, width=BAND_WIDTH,
style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}
),
Label(text=_(u"SINTER - Secretaria Especial do Interlegis"), top=1.5 * cm, left=0, width=BAND_WIDTH,
style={'fontName': 'Helvetica-Bold', 'fontSize': 13, 'alignment': TA_CENTER}
),
SystemField(
expression='%(report_title)s', top=2.5 * cm, left=0, width=BAND_WIDTH,
style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}
),
Label(
text=_(u"UF"),
left=label_left[0] * cm,
top=label_top,
),
Label(
text=_(u"Municipio"),
left=label_left[1] * cm,
top=label_top,
),
Label(
text=_(u"Presidente"),
left=label_left[2] * cm,
top=label_top,
),
Label(
text=_(u"Endereço"),
left=label_left[3] * cm,
top=label_top,
),
Label(
text=_(u"Endereço na Internet"),
left=label_left[4] * cm,
top=label_top,
),
Label(
text=_(u"Email"),
left=label_left[5] * cm,
top=label_top,
),
]
class band_page_footer(ReportDefault.band_page_footer):
pass
class band_detail(ReportDefault.band_detail):
label_left = [0.3, 1, 5.5, 11, 17, 22]
elements = [
ObjectValue(
attribute_name='municipio.uf.sigla',
left=label_left[0] * cm,
width=1 * cm,
),
ObjectValue(
attribute_name='municipio.nome',
left=label_left[1] * cm,
),
ObjectValue(
attribute_name='presidente',
left=label_left[2] * cm,
),
ObjectValue(
attribute_name='logradouro',
left=label_left[3] * cm,
get_value=lambda instance: instance.logradouro + ' - ' + instance.bairro,
),
ObjectValue(
attribute_name='pagina_web',
left=label_left[4] * cm,
),
ObjectValue(
attribute_name='email',
left=label_left[5] * cm,
),
]
groups = [
ReportGroup(attribute_name='municipio.uf',
band_header=ReportBand(
height=0.7 * cm,
elements=[
ObjectValue(attribute_name='municipio.uf')
],
borders={'top': True},
)
)
]
class CasasSemConvenioReport(CasasLegislativasReport):
title = _(u'Relatório de Casas Legislativas sem Convênio')

132
sigi/apps/casas/templates/casas/report_pdf.html

@ -0,0 +1,132 @@
{% load smart_if %}
{% load static from staticfiles %}
{% load i18n %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Casa Legislativa</title>
<style type="text/css">
table {
padding: 3px;
line-height: 1em;
-fs-table-paginate: paginate;
}
thead {
display: table-header-group;
}
th {
font-weight: bold;
text-align: left;
}
th, td {
border-bottom: 1px solid #ddd;
}
td.logo {
text-align: center;
}
td.header_text p {
margin: 0px;
font-size: 1.4em;
}
td.header_text {
width: 550px;
}
h1 {
font-size: 2em;
text-align: center;
}
h2 {
font-size: 1.7em;
}
h3 {
margin-top: 10px;
margin-bottom: 0px;
}
body {
font-family: "Helvetica, Arial, sans-serif";
font-size: 1.3em;
line-height: 1em;
}
#footer {
text-align: center;
}
@page {
size: a4 landscape;
margin: 3.5cm 2cm 2cm 2cm;
font-family: "Helvetica, Arial, sans-serif";
font-size: 2em;
@frame header {
-pdf-frame-content: header;
top: 1cm;
}
@frame footer {
-pdf-frame-content: footer;
bottom: 0cm;
margin-left: 2cm;
margin-right: 2cm;
height: 1cm;
}
}
</style>
</head>
<body>
<div id="header">
<table>
<tr>
<td class="logo"><img src="{% static 'img/logo-senado.jpg' %}"/></td>
<td class="header_text">
<p><strong>{% trans 'SENADO FEDERAL' %}</strong></p>
<p><strong>{% trans 'ILB - Interlegis' %}</strong></p>
<p>{{ title }}</p>
</td>
<td class="logo"><img src="{% static 'img/logo-interlegis.jpg' %}"/></td>
</tr>
</table>
</div>
<table repeat="1">
<thead>
<tr>
<th style="width: 22.5%;">{% trans 'Casa' %}</th>
<th style="width: 12.5%;">{% trans 'Presidente' %}</th>
<th style="width: 5%;">{% trans 'Tipo' %}</th>
<th style="width: 18%;">{% trans 'Endereço' %}</th>
<th style="width: 10%;">{% trans 'Bairro' %}</th>
<th style="width: 7%;">{% trans 'CEP' %}</th>
<th style="width: 12.5%;">{% trans 'Telefone' %}</th>
<th style="width: 12.5%;">{% trans 'E-mail' %}</th>
</tr>
</thead>
{% for casa in casas %}
{% ifchanged casa.municipio.uf %}
<tr><td colspan="8"><h3>{{ casa.municipio.uf.nome }}</h3></td></tr>
{% endifchanged %}
<tr>
<td>{{ casa.nome }}</td>
<td>{{ casa.presidente }}</td>
<td>{{ casa.tipo.sigla }}</td>
<td>{{ casa.logradouro }}</td>
<td>{{ casa.bairro }}</td>
<td>{{ casa.cep }}</td>
<td>{{ casa.telefone }}</td>
<td>{{ casa.email }}</td>
</tr>
{% endfor %}
</table>
<div id="footer">
{%block page_foot%}
{% trans 'Página' %} <pdf:pagenumber>
{%endblock%}
</div>
</body>
</html>

24
sigi/apps/casas/views.py

@ -13,9 +13,7 @@ from django.utils.translation import ugettext as _, ungettext
from sigi.apps.casas.forms import PortfolioForm from sigi.apps.casas.forms import PortfolioForm
from sigi.apps.casas.models import CasaLegislativa from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.casas.reports import (CasasLegislativasLabels, from sigi.apps.casas.reports import (CasasLegislativasLabels,
CasasLegislativasLabelsSemPresidente, CasasLegislativasLabelsSemPresidente)
CasasLegislativasReport,
CasasSemConvenioReport)
from sigi.apps.contatos.models import UnidadeFederativa, Mesorregiao, Microrregiao from sigi.apps.contatos.models import UnidadeFederativa, Mesorregiao, Microrregiao
from sigi.apps.ocorrencias.models import Ocorrencia from sigi.apps.ocorrencias.models import Ocorrencia
from sigi.apps.parlamentares.reports import ParlamentaresLabels from sigi.apps.parlamentares.reports import ParlamentaresLabels
@ -261,13 +259,11 @@ def report(request, id=None, tipo=None):
if not qs: if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
# qs.order_by('municipio__uf','nome') qs = qs.order_by('municipio__uf', 'nome')
response = HttpResponse(content_type='application/pdf') context = {'casas': qs, 'title': _(u"Relação de Casas Legislativas")}
response['Content-Disposition'] = 'attachment; filename=casas.pdf'
report = CasasLegislativasReport(queryset=qs) return render_to_pdf('casas/report_pdf.html', context)
report.generate_by(PDFGenerator, filename=response)
return response
@login_required @login_required
@ -293,10 +289,10 @@ def casas_sem_convenio_report(request):
if not qs: if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
response = HttpResponse(content_type='application/pdf') qs = qs.order_by('municipio__uf', 'nome')
report = CasasSemConvenioReport(queryset=qs) context = {'casas': qs, 'title': _(u"Casas sem convênio")}
report.generate_by(PDFGenerator, filename=response)
return response return render_to_pdf('casas/report_pdf.html', context)
@login_required @login_required

Loading…
Cancel
Save