From 9f774e77fa52a7c4704b32612ebfdf0609dccc40 Mon Sep 17 00:00:00 2001 From: "Starlone (Estagiario)" Date: Fri, 22 Oct 2010 17:58:30 +0000 Subject: [PATCH] =?UTF-8?q?Alterando=20gera=C3=A7=C3=A3o=20de=20etiquetas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/casas/reports.py | 143 +++++-------------------------------- sigi/apps/casas/views.py | 112 ++--------------------------- 2 files changed, 20 insertions(+), 235 deletions(-) diff --git a/sigi/apps/casas/reports.py b/sigi/apps/casas/reports.py index d4d8e64..424908d 100644 --- a/sigi/apps/casas/reports.py +++ b/sigi/apps/casas/reports.py @@ -62,154 +62,43 @@ class CasasLegislativasLabels(Report): width = 9.9*cm height = 5.6*cm margin_bottom = 0.0*cm - margin_right = 0.3*cm + margin_right = 0.3*cm # With this attribute as True, the band will try to align in # the same line. - display_inline = True + display_inline = True - default_style = {'fontName': 'Helvetica', 'fontSize': 11} - - elements = [ - Label( - text='A Sua Excelência o(a) Senhor(a)', - top=1*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='presidente', - top=1.5*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='nome', - top=2*cm, left=0.5*cm, width=9.4*cm, - get_value=lambda instance: - "Presidente da " + instance.nome - ), - ObjectValue( - attribute_name='logradouro', - top=2.5*cm, left=0.5*cm, width=9.4*cm, - get_value=lambda instance: - (instance.logradouro +" - "+ instance.bairro) - if len(instance.bairro) != 0 - else instance.logradouro - ), - ObjectValue( - attribute_name='municipio', - top=3*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='cep', - top=3.5*cm, left=0.5*cm, width=9.4*cm, - ), - ] + default_style = {'fontName': 'Helvetica', 'fontSize': 11} -class CasasLabelsNomeMaior(CasasLegislativasLabels): - class band_detail(CasasLegislativasLabels.band_detail): - elements = [ - Label( - text='A Sua Excelência o(a) Senhor(a)', - top=1*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='presidente', - top=1.5*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='nome', - top=2*cm, left=0.5*cm, width=9.4*cm, - get_value=lambda instance: - "Presidente da " + instance.nome - ), - ObjectValue( - attribute_name='logradouro', - top=3*cm, left=0.5*cm, width=9.4*cm, - get_value=lambda instance: - instance.logradouro +" - "+ instance.bairro - if len(instance.bairro) != 0 - else instance.logradouro - ), - ObjectValue( - attribute_name='municipio', - top=3.5*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='cep', - top=4*cm, left=0.5*cm, width=9.4*cm, - ), - ] -class CasasLabelsEnderecoMaior(CasasLegislativasLabels): - class band_detail(CasasLegislativasLabels.band_detail): elements = [ Label( text='A Sua Excelência o(a) Senhor(a)', top=1*cm, left=0.5*cm, width=9.4*cm, ), ObjectValue( - attribute_name='presidente', + attribute_name='tipo', top=1.5*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='nome', - top=2*cm, left=0.5*cm, width=9.4*cm, get_value=lambda instance: - "Presidente da " + instance.nome - ), - ObjectValue( - attribute_name='logradouro', - top=2.5*cm, left=0.5*cm, width=9.4*cm, - get_value=lambda instance: - instance.logradouro +" - "+ instance.bairro - if len(instance.bairro) != 0 - else instance.logradouro - ), - ObjectValue( - attribute_name='municipio', - top=3.5*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='cep', - top=4*cm, left=0.5*cm, width=9.4*cm, - ), - ] - -class CasasLabelsNomeMaiorEnderecoMaior(CasasLegislativasLabels): - class band_detail(CasasLegislativasLabels.band_detail): - elements = [ - Label( - text='A Sua Excelência o(a) Senhor(a)', - top=1*cm, left=0.5*cm, width=9.4*cm, - ), - ObjectValue( - attribute_name='presidente', - top=1.5*cm, left=0.5*cm, width=9.4*cm, + "Presidente da " + instance.tipo.nome + " de " ), ObjectValue( attribute_name='nome', top=2*cm, left=0.5*cm, width=9.4*cm, get_value=lambda instance: - "Presidente da " + instance.nome - ), - ObjectValue( - attribute_name='logradouro', - top=3*cm, left=0.5*cm, width=9.4*cm, - get_value=lambda instance: - instance.logradouro +" - "+ instance.bairro - if len(instance.bairro) != 0 - else instance.logradouro - ), - ObjectValue( - attribute_name='municipio', - top=4*cm, left=0.5*cm, width=9.4*cm, + instance.municipio.uf.nome + if instance.tipo.nome == u'Assembléia Legislativa' + else instance.municipio.nome + ), - ObjectValue( - attribute_name='cep', - top=4.5*cm, left=0.5*cm, width=9.4*cm, + ManyElements( + ObjectValue, + count=4, + attribute_name=('logradouro','bairro','municipio','cep'), + start_top=2.5*cm, height=0.5*cm, left=0.5*cm, width=9.4*cm, ), - ] - - + ] class CasasLegislativasReport(ReportDefault): title = u'Relatório de Casas Legislativas' @@ -560,4 +449,4 @@ class InfoCasaLegislativa(ReportDefault): ) ] - \ No newline at end of file + diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index 0c3e398..50eb9f2 100644 --- a/sigi/apps/casas/views.py +++ b/sigi/apps/casas/views.py @@ -4,18 +4,11 @@ from geraldo.generators import PDFGenerator from sigi.apps.casas.models import CasaLegislativa from sigi.apps.casas.reports import CasasLegislativasLabels -from sigi.apps.casas.reports import CasasLabelsNomeMaior -from sigi.apps.casas.reports import CasasLabelsEnderecoMaior -from sigi.apps.casas.reports import CasasLabelsNomeMaiorEnderecoMaior - from sigi.apps.casas.reports import CasasLegislativasReport from sigi.apps.casas.reports import CasasSemConvenioReport from sigi.apps.casas.reports import InfoCasaLegislativa -import csv - -from sigi.apps.casas.reports import string_to_cm -from reportlab.lib.units import cm +import csv def labels_report(request, id=None,queryset=None): """ TODO: adicionar suporte para resultado de pesquisa do admin. @@ -31,111 +24,14 @@ def labels_report(request, id=None,queryset=None): for k, v in request.GET.iteritems(): kwargs[str(k)] = v qs = qs.filter(**kwargs) - - - casasNormais = [] - casasNomesGrandes = [] - casasEnderecoGrande = [] - casasNomeEnderecoGrande = [] - tamanho = 8.2 - for casa in qs: - tamNome = string_to_cm("Presidente da " + casa.nome) - tamEnder = string_to_cm((casa.logradouro +" - "+ casa.bairro) - if len(casa.bairro) != 0 - else casa.logradouro - ) - if tamNome tamanho: - casasEnderecoGrande.append(casa) - elif tamNome >tamanho and tamEnder < tamanho: - casasNomesGrandes.append(casa) - else: - casasNomeEnderecoGrande.append(casa) response = HttpResponse(mimetype='application/pdf') - - cN = len(casasNormais) - cNoG = len(casasNomesGrandes) - cEG = len(casasEnderecoGrande) - cNoEG = len(casasNomeEnderecoGrande) - - # Testando se as listas não estão vazias e criando os reports - report1=report2=report3=report4=None - canvas = None - if cN: - report1 = CasasLegislativasLabels(queryset=casasNormais) - if cNoG or cEG or cNoEG: - canvas = report1.generate_by( - PDFGenerator, - filename=response,return_canvas=True, - ) - else: - report1.generate_by(PDFGenerator, filename=response) - - if cNoG: - report2 = CasasLabelsNomeMaior(queryset=casasNomesGrandes) - if cEG or cNoEG: - if canvas: - canvas = report2.generate_by( - PDFGenerator, - canvas=canvas, - return_canvas=True, - ) - else: - canvas = report2.generate_by( - PDFGenerator, - canvas=canvas, - return_canvas=True, - filename=response, - ) - else: - if canvas: - report2.generate_by( - PDFGenerator, - canvas=canvas, - ) - else: - report2.generate_by(PDFGenerator, filename=response) - - if cEG: - report3 = CasasLabelsEnderecoMaior(queryset=casasEnderecoGrande) - if cNoEG: - if canvas: - canvas = report3.generate_by( - PDFGenerator, - canvas=canvas, - return_canvas=True, - ) - else: - canvas = report3.generate_by( - PDFGenerator, - canvas=canvas, - return_canvas=True, - filename=response, - ) - else: - if canvas: - report3.generate_by( - PDFGenerator, - canvas=canvas, - ) - else: - report3.generate_by(PDFGenerator, filename=response) - - - if cNoEG: - report4 = CasasLabelsNomeMaiorEnderecoMaior(queryset=casasNomeEnderecoGrande) - if canvas: - report4.generate_by( - PDFGenerator, - canvas=canvas, - ) - else: - report4.generate_by(PDFGenerator, filename=response) + report = CasasLegislativasLabels(queryset=qs) + report.generate_by(PDFGenerator, filename=response) return response + def report(request, id=None): qs = CasaLegislativa.objects.all().order_by('municipio__uf','nome') if id: