Browse Source

Adicionado novo formato de etiqueta

stable/1.0
Breno Teixeira 12 years ago
parent
commit
b1ebc551dd
  1. 2
      .gitignore
  2. 83
      sigi/apps/casas/reports.py
  3. 9
      sigi/apps/casas/templates/casas/carrinho.html
  4. 10
      sigi/apps/casas/views.py

2
.gitignore

@ -33,3 +33,5 @@ nosetests.xml
.mr.developer.cfg .mr.developer.cfg
.project .project
.pydevproject .pydevproject
.settings
.gitignore

83
sigi/apps/casas/reports.py

@ -51,47 +51,57 @@ class CasasLegislativasLabels(Report):
>>> report.generate_by(PDFGenerator, filename='./inline-detail-report.pdf') >>> report.generate_by(PDFGenerator, filename='./inline-detail-report.pdf')
""" """
formato = ''
page_size = A4 y = 2
margin_top = 0.8*cm largura_etiqueta = 6.7
margin_bottom = 0.8*cm altura_etiqueta = 3.3
margin_left = 0.4*cm tamanho_fonte = 6
margin_right = 0.4*cm altura_dados = 0.3 #logradouro, bairro, municipio, cep
delta = start = 0.5
class band_detail(DetailBand):
def __init__(self, queryset, formato):
super(CasasLegislativasLabels, self).__init__(queryset=queryset)
width = 9.9*cm self.formato = formato
height = 5.6*cm self.page_size = A4
margin_bottom = 0.0*cm
margin_right = 0.3*cm if formato == '3x9_etiqueta':
self.margin_top = 0.0*cm
# With this attribute as True, the band will try to align in self.margin_bottom = 0.0*cm
# the same line. self.margin_left = 0.0*cm
display_inline = True self.margin_right = 0.0*cm
self.delta = 0.3
default_style = {'fontName': 'Helvetica', 'fontSize': 11} self.start = 0.2
else:
elements = [ 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( Label(
text='A Sua Excelência o(a) Senhor(a)', 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( ObjectValue(
attribute_name='presidente', 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: get_value=lambda instance:
instance.presidente or "" instance.presidente or ""
), ),
ObjectValue( ObjectValue(
attribute_name='tipo', 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: get_value=lambda instance:
"Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2] "Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2]
), ),
ObjectValue( ObjectValue(
attribute_name='nome', 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: get_value=lambda instance:
instance.municipio.uf.nome instance.municipio.uf.nome
if instance.tipo.nome == u'Assembléia Legislativa' if instance.tipo.nome == u'Assembléia Legislativa'
@ -102,31 +112,32 @@ class CasasLegislativasLabels(Report):
ObjectValue, ObjectValue,
count=4, count=4,
attribute_name=('logradouro','bairro','municipio','cep'), 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 CasasLegislativasLabelsSemPresidente(CasasLegislativasLabels):
def __init__(self, queryset, formato):
super(CasasLegislativasLabelsSemPresidente, self).__init__(queryset=queryset, formato=formato)
class band_detail(CasasLegislativasLabels.band_detail):
elements = [ my_elements = [
Label( Label(
text='A Sua Excelência o(a) Senhor(a)', 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( ObjectValue(
attribute_name='tipo', 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: get_value=lambda instance:
"Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2] "Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2]
), ),
ObjectValue( ObjectValue(
attribute_name='nome', 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: get_value=lambda instance:
instance.municipio.uf.nome instance.municipio.uf.nome
if instance.tipo.nome == u'Assembléia Legislativa' if instance.tipo.nome == u'Assembléia Legislativa'
@ -137,11 +148,13 @@ class CasasLegislativasLabelsSemPresidente(CasasLegislativasLabels):
ObjectValue, ObjectValue,
count=4, count=4,
attribute_name=('logradouro','bairro','municipio','cep'), 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): class CasasLegislativasReport(ReportDefault):
title = u'Relatório de Casas Legislativas' title = u'Relatório de Casas Legislativas'

9
sigi/apps/casas/templates/casas/carrinho.html

@ -72,6 +72,15 @@
<label>Sem Presidente</label></li> <label>Sem Presidente</label></li>
</ul> </ul>
</fieldset> </fieldset>
<fieldset><legend>Formato da Etiqueta</legend>
<ul class="formato_etiqueta">
<li><input type="radio" name="tamanho_etiqueta"
value="2x5_etiqueta"><label>2x5</label></li>
<li><input type="radio" name="tamanho_etiqueta"
value="3x9_etiqueta" checked="checked"><label>3x9</label></li>
</ul>
</fieldset>
<ul class="botoes"> <ul class="botoes">
<li><input type="submit" value="Gerar Etiqueta" /></li> <li><input type="submit" value="Gerar Etiqueta" /></li>
</ul> </ul>

10
sigi/apps/casas/views.py

@ -131,9 +131,11 @@ def labels_report(request, id=None, tipo=None):
if request.POST: if request.POST:
if request.POST.has_key('tipo_etiqueta'): if request.POST.has_key('tipo_etiqueta'):
tipo = request.POST['tipo_etiqueta'] tipo = request.POST['tipo_etiqueta']
if request.POST.has_key('tamanho_etiqueta'):
formato = request.POST['tamanho_etiqueta']
if tipo =='sem_presidente': if tipo =='sem_presidente':
return labels_report_sem_presidente(request, id) return labels_report_sem_presidente(request, id, formato)
if id: if id:
qs = CasaLegislativa.objects.filter(pk=id) qs = CasaLegislativa.objects.filter(pk=id)
@ -145,12 +147,12 @@ def labels_report(request, id=None, tipo=None):
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=casas.pdf' response['Content-Disposition'] = 'attachment; filename=casas.pdf'
report = CasasLegislativasLabels(queryset=qs) report = CasasLegislativasLabels(queryset=qs, formato=formato)
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return 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. """ TODO: adicionar suporte para resultado de pesquisa do admin.
""" """
@ -164,7 +166,7 @@ def labels_report_sem_presidente(request, id=None):
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=casas.pdf' response['Content-Disposition'] = 'attachment; filename=casas.pdf'
report = CasasLegislativasLabelsSemPresidente(queryset=qs) report = CasasLegislativasLabelsSemPresidente(queryset=qs, formato=formato)
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return response return response

Loading…
Cancel
Save