Browse Source

Alterando geração de etiquetas

diagnosticos
Starlone (Estagiario) 14 years ago
parent
commit
9f774e77fa
  1. 143
      sigi/apps/casas/reports.py
  2. 112
      sigi/apps/casas/views.py

143
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):
)
]

112
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 and tamEnder <tamanho:
casasNormais.append(casa)
elif tamNome <tamanho and tamEnder > 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:

Loading…
Cancel
Save