From b1ebc551dd47cf9dbcf227bdd117c1c4de5a3ae1 Mon Sep 17 00:00:00 2001 From: Breno Teixeira Date: Wed, 28 Nov 2012 10:56:24 -0200 Subject: [PATCH] Adicionado novo formato de etiqueta --- .gitignore | 2 + sigi/apps/casas/reports.py | 89 +++++++++++-------- sigi/apps/casas/templates/casas/carrinho.html | 9 ++ sigi/apps/casas/views.py | 12 +-- 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index d2d6f36..241cef0 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ nosetests.xml .mr.developer.cfg .project .pydevproject +.settings +.gitignore diff --git a/sigi/apps/casas/reports.py b/sigi/apps/casas/reports.py index ea69c93..e64af08 100644 --- a/sigi/apps/casas/reports.py +++ b/sigi/apps/casas/reports.py @@ -51,47 +51,57 @@ class CasasLegislativasLabels(Report): >>> report.generate_by(PDFGenerator, filename='./inline-detail-report.pdf') """ - - page_size = A4 - margin_top = 0.8*cm - margin_bottom = 0.8*cm - margin_left = 0.4*cm - margin_right = 0.4*cm - - class band_detail(DetailBand): - - - width = 9.9*cm - height = 5.6*cm - margin_bottom = 0.0*cm - margin_right = 0.3*cm - - # With this attribute as True, the band will try to align in - # the same line. - display_inline = True - - default_style = {'fontName': 'Helvetica', 'fontSize': 11} - - elements = [ + formato = '' + y = 2 + largura_etiqueta = 6.7 + altura_etiqueta = 3.3 + tamanho_fonte = 6 + altura_dados = 0.3 #logradouro, bairro, municipio, cep + delta = start = 0.5 + + def __init__(self, queryset, formato): + super(CasasLegislativasLabels, self).__init__(queryset=queryset) + self.formato = formato + self.page_size = A4 + + if formato == '3x9_etiqueta': + self.margin_top = 0.0*cm + self.margin_bottom = 0.0*cm + self.margin_left = 0.0*cm + self.margin_right = 0.0*cm + self.delta = 0.3 + self.start = 0.2 + else: + self.margin_top = 0.8*cm + self.margin_bottom = 0.8*cm + self.margin_left = 0.4*cm + self.margin_right = 0.4*cm + self.largura_etiqueta = 9.9 + self.altura_etiqueta = 5.6 + self.tamanho_fonte = 11 + self.altura_dados = 0.5 + self.y = 0.5 + + my_elements = [ Label( text='A Sua Excelência o(a) Senhor(a)', - top=1*cm, left=0.5*cm, width=9.4*cm, + top=(self.start + self.delta)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, ), ObjectValue( attribute_name='presidente', - top=1.5*cm, left=0.5*cm, width=9.4*cm, + top=(self.start + 2*self.delta)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, get_value=lambda instance: instance.presidente or "" ), ObjectValue( attribute_name='tipo', - top=2*cm, left=0.5*cm, width=9.4*cm, + top=(self.start + 3*self.delta)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, get_value=lambda instance: "Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2] ), ObjectValue( attribute_name='nome', - top=2.5*cm, left=0.5*cm, width=9.4*cm, + top=(self.start + 4*self.delta)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, get_value=lambda instance: instance.municipio.uf.nome if instance.tipo.nome == u'Assembléia Legislativa' @@ -102,31 +112,32 @@ class CasasLegislativasLabels(Report): ObjectValue, count=4, attribute_name=('logradouro','bairro','municipio','cep'), - start_top=3*cm, height=0.5*cm, left=0.5*cm, width=9.4*cm, + start_top=(self.start + 5*self.delta)*cm, height=(self.altura_dados)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, ), - ] + ] + self.band_detail = DetailBand(width=(self.largura_etiqueta)*cm, height=(self.altura_etiqueta)*cm, margin_left = 0, margin_top = 0, margin_bottom=0.0*cm, margin_right = 0, elements=my_elements,display_inline=True, default_style={'fontName': 'Helvetica', 'fontSize': self.tamanho_fonte}) - - class CasasLegislativasLabelsSemPresidente(CasasLegislativasLabels): - - class band_detail(CasasLegislativasLabels.band_detail): - elements = [ + def __init__(self, queryset, formato): + super(CasasLegislativasLabelsSemPresidente, self).__init__(queryset=queryset, formato=formato) + + + my_elements = [ Label( text='A Sua Excelência o(a) Senhor(a)', - top=1*cm, left=0.5*cm, width=9.4*cm, + top=(self.start + self.delta)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, ), ObjectValue( attribute_name='tipo', - top=1.5*cm, left=0.5*cm, width=9.4*cm, + top=(self.start + 3*self.delta)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, get_value=lambda instance: "Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2] ), ObjectValue( attribute_name='nome', - top=2*cm, left=0.5*cm, width=9.4*cm, + top=(self.start + 4*self.delta)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, get_value=lambda instance: instance.municipio.uf.nome if instance.tipo.nome == u'Assembléia Legislativa' @@ -137,11 +148,13 @@ class CasasLegislativasLabelsSemPresidente(CasasLegislativasLabels): 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, + start_top=(self.start + 5*self.delta)*cm, height=(self.altura_dados)*cm, left=self.y*cm, width=(self.largura_etiqueta-self.y)*cm, ), ] - + + self.band_detail = DetailBand(width=(self.largura_etiqueta)*cm, height=(self.altura_etiqueta)*cm, margin_left = 0, margin_top = 0, margin_bottom=0.0*cm, margin_right = 0, elements=my_elements,display_inline=True, default_style={'fontName': 'Helvetica', 'fontSize': self.tamanho_fonte}) + class CasasLegislativasReport(ReportDefault): title = u'Relatório de Casas Legislativas' diff --git a/sigi/apps/casas/templates/casas/carrinho.html b/sigi/apps/casas/templates/casas/carrinho.html index 9774a6f..11cf8e5 100644 --- a/sigi/apps/casas/templates/casas/carrinho.html +++ b/sigi/apps/casas/templates/casas/carrinho.html @@ -72,6 +72,15 @@ +
Formato da Etiqueta + +
diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index 0f0af38..7940da9 100644 --- a/sigi/apps/casas/views.py +++ b/sigi/apps/casas/views.py @@ -131,9 +131,11 @@ def labels_report(request, id=None, tipo=None): if request.POST: if request.POST.has_key('tipo_etiqueta'): tipo = request.POST['tipo_etiqueta'] + if request.POST.has_key('tamanho_etiqueta'): + formato = request.POST['tamanho_etiqueta'] if tipo =='sem_presidente': - return labels_report_sem_presidente(request, id) + return labels_report_sem_presidente(request, id, formato) if id: qs = CasaLegislativa.objects.filter(pk=id) @@ -145,15 +147,15 @@ def labels_report(request, id=None, tipo=None): response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=casas.pdf' - report = CasasLegislativasLabels(queryset=qs) + report = CasasLegislativasLabels(queryset=qs, formato=formato) report.generate_by(PDFGenerator, filename=response) return response -def labels_report_sem_presidente(request, id=None): +def labels_report_sem_presidente(request, id=None, formato='2x5_etiqueta'): """ TODO: adicionar suporte para resultado de pesquisa do admin. """ - + if id: qs = CasaLegislativa.objects.filter(pk=id) else: @@ -164,7 +166,7 @@ def labels_report_sem_presidente(request, id=None): response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=casas.pdf' - report = CasasLegislativasLabelsSemPresidente(queryset=qs) + report = CasasLegislativasLabelsSemPresidente(queryset=qs, formato=formato) report.generate_by(PDFGenerator, filename=response) return response