From 6bcb0ae5a96d888f5f9c0170c55ec24da39ce90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Fri, 14 Jun 2019 15:19:32 -0300 Subject: [PATCH] =?UTF-8?q?Usar=20pisa=20para=20mais=20alguns=20relat?= =?UTF-8?q?=C3=B3rios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/casas/reports.py | 116 --------------- .../casas/templates/casas/report_pdf.html | 132 ++++++++++++++++++ sigi/apps/casas/views.py | 24 ++-- 3 files changed, 142 insertions(+), 130 deletions(-) create mode 100644 sigi/apps/casas/templates/casas/report_pdf.html diff --git a/sigi/apps/casas/reports.py b/sigi/apps/casas/reports.py index d94a3fa..e6e27c3 100644 --- a/sigi/apps/casas/reports.py +++ b/sigi/apps/casas/reports.py @@ -177,119 +177,3 @@ class CasasLegislativasLabelsSemPresidente(CasasLegislativasLabels): display_inline=True, 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') diff --git a/sigi/apps/casas/templates/casas/report_pdf.html b/sigi/apps/casas/templates/casas/report_pdf.html new file mode 100644 index 0000000..485e7de --- /dev/null +++ b/sigi/apps/casas/templates/casas/report_pdf.html @@ -0,0 +1,132 @@ +{% load smart_if %} +{% load static from staticfiles %} +{% load i18n %} + + + + + Casa Legislativa + + + + + + + + + + + + + + + + + + + + {% for casa in casas %} + {% ifchanged casa.municipio.uf %} + + {% endifchanged %} + + + + + + + + + + + {% endfor %} +
{% trans 'Casa' %}{% trans 'Presidente' %}{% trans 'Tipo' %}{% trans 'Endereço' %}{% trans 'Bairro' %}{% trans 'CEP' %}{% trans 'Telefone' %}{% trans 'E-mail' %}

{{ casa.municipio.uf.nome }}

{{ casa.nome }}{{ casa.presidente }}{{ casa.tipo.sigla }}{{ casa.logradouro }}{{ casa.bairro }}{{ casa.cep }}{{ casa.telefone }}{{ casa.email }}
+ + + + diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index 97f5cdb..d760b85 100644 --- a/sigi/apps/casas/views.py +++ b/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.models import CasaLegislativa from sigi.apps.casas.reports import (CasasLegislativasLabels, - CasasLegislativasLabelsSemPresidente, - CasasLegislativasReport, - CasasSemConvenioReport) + CasasLegislativasLabelsSemPresidente) from sigi.apps.contatos.models import UnidadeFederativa, Mesorregiao, Microrregiao from sigi.apps.ocorrencias.models import Ocorrencia from sigi.apps.parlamentares.reports import ParlamentaresLabels @@ -261,13 +259,11 @@ def report(request, id=None, tipo=None): if not qs: return HttpResponseRedirect('../') - - # qs.order_by('municipio__uf','nome') - response = HttpResponse(content_type='application/pdf') - response['Content-Disposition'] = 'attachment; filename=casas.pdf' - report = CasasLegislativasReport(queryset=qs) - report.generate_by(PDFGenerator, filename=response) - return response + + qs = qs.order_by('municipio__uf', 'nome') + context = {'casas': qs, 'title': _(u"Relação de Casas Legislativas")} + + return render_to_pdf('casas/report_pdf.html', context) @login_required @@ -293,10 +289,10 @@ def casas_sem_convenio_report(request): if not qs: return HttpResponseRedirect('../') - response = HttpResponse(content_type='application/pdf') - report = CasasSemConvenioReport(queryset=qs) - report.generate_by(PDFGenerator, filename=response) - return response + qs = qs.order_by('municipio__uf', 'nome') + context = {'casas': qs, 'title': _(u"Casas sem convênio")} + + return render_to_pdf('casas/report_pdf.html', context) @login_required