Browse Source

Alterando geração de etiqueta da action e adicionando relatorio completo das casas

diagnosticos
Starlone (Estagiario) 15 years ago
parent
commit
d9adaca7ac
  1. 17
      sigi/apps/casas/admin.py
  2. 235
      sigi/apps/casas/reports.py
  3. 62
      sigi/apps/casas/views.py

17
sigi/apps/casas/admin.py

@ -9,6 +9,8 @@ from django.http import HttpResponse, HttpResponseRedirect
from sigi.apps.casas.reports import CasasLegislativasLabels, CasasLegislativasReport from sigi.apps.casas.reports import CasasLegislativasLabels, CasasLegislativasReport
from geraldo.generators import PDFGenerator from geraldo.generators import PDFGenerator
from sigi.apps.casas.views import casa_info, labels_report
class ContatosInline(generic.GenericTabularInline): class ContatosInline(generic.GenericTabularInline):
model = Contato model = Contato
extra = 2 extra = 2
@ -27,7 +29,7 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
form = CasaLegislativaForm form = CasaLegislativaForm
change_form_template = 'casas/change_form.html' change_form_template = 'casas/change_form.html'
change_list_template = 'casas/change_list.html' change_list_template = 'casas/change_list.html'
actions = ['etiqueta','relatorio'] actions = ['etiqueta','relatorio','relatorio_completo']
inlines = (TelefonesInline, ContatosInline, ConveniosInline) inlines = (TelefonesInline, ContatosInline, ConveniosInline)
list_display = ('nome','municipio','presidente','logradouro') list_display = ('nome','municipio','presidente','logradouro')
list_display_links = ('nome',) list_display_links = ('nome',)
@ -47,7 +49,7 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
}), }),
) )
raw_id_fields = ('municipio',) raw_id_fields = ('municipio',)
search_fields = ('nome', 'sigla', 'cnpj', 'logradouro', 'bairro', search_fields = ('nome','cnpj', 'logradouro', 'bairro',
'cep', 'municipio__nome', 'municipio__uf__nome', 'cep', 'municipio__nome', 'municipio__uf__nome',
'municipio__codigo_ibge', 'pagina_web', 'observacoes') 'municipio__codigo_ibge', 'pagina_web', 'observacoes')
@ -59,9 +61,7 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
def etiqueta(modelAdmin,request,queryset): def etiqueta(modelAdmin,request,queryset):
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
report = CasasLegislativasLabels(queryset=queryset) return labels_report(request,queryset=queryset)
report.generate_by(PDFGenerator, filename=response)
return response
etiqueta.short_description = "Gerar etiqueta(s) da(s) casa(s) selecionada(s)" etiqueta.short_description = "Gerar etiqueta(s) da(s) casa(s) selecionada(s)"
def relatorio(modelAdmin,request,queryset): def relatorio(modelAdmin,request,queryset):
@ -69,7 +69,12 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
report = CasasLegislativasReport(queryset=queryset) report = CasasLegislativasReport(queryset=queryset)
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return response return response
relatorio.short_description = u"Gerar relatório(s) da(s) casa(s) selecionada(s)" relatorio.short_description = u"Gerar relatório resumido da(s) casa(s) selecionada(s)"
def relatorio_completo(modelAdmin,request,queryset):
response = HttpResponse(mimetype='application/pdf')
return casa_info(request,queryset=queryset)
relatorio_completo.short_description = u"Gerar relatório completo da(s) casa(s) selecionada(s)"
def get_actions(self, request): def get_actions(self, request):
actions = super(CasaLegislativaAdmin, self).get_actions(request) actions = super(CasaLegislativaAdmin, self).get_actions(request)

235
sigi/apps/casas/reports.py

@ -76,7 +76,7 @@ class CasasLegislativasLabels(Report):
top=1*cm, left=0.5*cm, width=9.4*cm, top=1*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='parlamentar', attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm, top=1.5*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
@ -111,7 +111,7 @@ class CasasLabelsNomeMaior(CasasLegislativasLabels):
top=1*cm, left=0.5*cm, width=9.4*cm, top=1*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='parlamentar', attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm, top=1.5*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
@ -146,7 +146,7 @@ class CasasLabelsEnderecoMaior(CasasLegislativasLabels):
top=1*cm, left=0.5*cm, width=9.4*cm, top=1*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='parlamentar', attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm, top=1.5*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
@ -181,7 +181,7 @@ class CasasLabelsNomeMaiorEnderecoMaior(CasasLegislativasLabels):
top=1*cm, left=0.5*cm, width=9.4*cm, top=1*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='parlamentar', attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm, top=1.5*cm, left=0.5*cm, width=9.4*cm,
), ),
ObjectValue( ObjectValue(
@ -213,6 +213,7 @@ class CasasLabelsNomeMaiorEnderecoMaior(CasasLegislativasLabels):
class CasasLegislativasReport(ReportDefault): class CasasLegislativasReport(ReportDefault):
title = u'Relatório de Casas Legislativas' title = u'Relatório de Casas Legislativas'
height = 80*cm
class band_page_header(ReportDefault.band_page_header): class band_page_header(ReportDefault.band_page_header):
@ -263,7 +264,7 @@ class CasasLegislativasReport(ReportDefault):
left=label_left[1]*cm, left=label_left[1]*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='parlamentar', attribute_name='presidente',
left=label_left[2]*cm, left=label_left[2]*cm,
), ),
ObjectValue( ObjectValue(
@ -290,27 +291,32 @@ class CasasSemConvenioReport(CasasLegislativasReport):
title = u'Relatório de Casas Legislativas sem Convênio' title = u'Relatório de Casas Legislativas sem Convênio'
class InfoCasaLegislativa(ReportDefault): class InfoCasaLegislativa(ReportDefault):
title = u'Casa legislativa'
class band_detail(ReportDefault.band_detail): class band_detail(ReportDefault.band_detail):
posicao_left = [ posicao_left = [
0,1.3, #Tipo
0,1.8, #Regiao 0,1.8, #Regiao
5.5,6.8, #U.F. 5.5,6.8, #U.F.
12,13.3, #Tipo
0,2.3, #Municipio 0,2.3, #Municipio
0,2.8, #Logradouro 0,2.8, #Logradouro
0,1.6, #Bairro 0,1.6, #Bairro
0,1.3, #CEP 0,1.3, #CEP
0,1.6, #CNPJ
0,2.3, #Telefone
0,2.7, #Presidente 0,2.7, #Presidente
] ]
posicao_top = [ posicao_top = [
0.5, #Regiao
0.5, #U.F.
0.5, #Tipo 0.5, #Tipo
1.3, #Municipio 1.3, #Regiao
2.1, #Logradouro 1.3, #U.F.
2.9, #Bairro 2.1, #Municipio
3.7, #CEP 2.9, #Logradouro
4.5, #Presidente 3.7, #Bairro
4.5, #CEP
5.3, #CNPJ
6.1, #Telefone
6.9, #Presidente
] ]
height=30*cm height=30*cm
@ -320,42 +326,40 @@ class InfoCasaLegislativa(ReportDefault):
elements = [ elements = [
# Linha 1
Label( Label(
text="Região: ", text="Tipo: ",
left=posicao_left[0]*cm, left=posicao_left[0]*cm,
top=posicao_top[0]*cm, top=posicao_top[0]*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='municipio.uf.regiao', attribute_name='tipo.nome',
left=posicao_left[1]*cm, left=posicao_left[1]*cm,
top=posicao_top[0]*cm, top=posicao_top[0]*cm,
get_value=lambda instance: width=6*cm,
{'SL': 'Sul','SD': 'Sudeste','CO': 'Centro-Oeste','NE': 'Nordeste','NO': 'Norte',}
[instance.municipio.uf.regiao]
), ),
Label( Label(
text="U.F.: ", text="Região: ",
left=posicao_left[2]*cm, left=posicao_left[2]*cm,
top=posicao_top[1]*cm, top=posicao_top[1]*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='municipio.uf', attribute_name='municipio.uf.regiao',
left=posicao_left[3]*cm, left=posicao_left[3]*cm,
top=posicao_top[1]*cm, top=posicao_top[1]*cm,
get_value=lambda instance:
{'SL': 'Sul','SD': 'Sudeste','CO': 'Centro-Oeste','NE': 'Nordeste','NO': 'Norte',}
[instance.municipio.uf.regiao]
), ),
Label( Label(
text="Tipo: ", text="U.F.: ",
left=posicao_left[4]*cm, left=posicao_left[4]*cm,
top=posicao_top[2]*cm, top=posicao_top[2]*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='tipo.nome', attribute_name='municipio.uf',
left=posicao_left[5]*cm, left=posicao_left[5]*cm,
top=posicao_top[2]*cm, top=posicao_top[2]*cm,
width=6*cm,
), ),
# Linha 2
Label( Label(
text="Município: ", text="Município: ",
left=posicao_left[6]*cm, left=posicao_left[6]*cm,
@ -400,25 +404,116 @@ class InfoCasaLegislativa(ReportDefault):
top=posicao_top[6]*cm, top=posicao_top[6]*cm,
), ),
Label( Label(
text="Presidente: ", text="CNPJ: ",
left=posicao_left[14]*cm, left=posicao_left[14]*cm,
top=posicao_top[7]*cm, top=posicao_top[7]*cm,
), ),
ObjectValue( ObjectValue(
attribute_name='parlamentar', attribute_name='cnpj',
left=posicao_left[15]*cm, left=posicao_left[15]*cm,
top=posicao_top[7]*cm, top=posicao_top[7]*cm,
),
Label(
text="Telefone: ",
left=posicao_left[16]*cm,
top=posicao_top[8]*cm,
),
ObjectValue(
attribute_name='telefone',
left=posicao_left[17]*cm,
top=posicao_top[8]*cm,
),
Label(
text="Presidente: ",
left=posicao_left[18]*cm,
top=posicao_top[9]*cm,
),
ObjectValue(
attribute_name='presidente',
left=posicao_left[19]*cm,
top=posicao_top[9]*cm,
width=20*cm, width=20*cm,
), ),
] ]
label_top = 1.5*cm # Telefones
label_left = [0,1.5,4,8,10.5,13,15.5,18] tel_top = 2*cm
tel_left = [0,3,5]
# Contato
cont_top = 2*cm
cont_left = [0,6,9]
# Convenios
convenio_top = 2*cm
convenio_left = [0,1.8,4.5,8,10.5,13,15.5,18]
subreports = [ subreports = [
# Telefones
SubReport(
queryset_string = '%(object)s.telefones.all()',
band_header = ReportBand(
default_style = {'fontName': 'Helvetica', 'fontSize':12 },
height=2.5*cm,
elements = [
Label(
text="Telefone(s)",
style = {'fontSize':14,'alignment': TA_CENTER},
width=BAND_WIDTH,
top=1*cm,
),
Label(text="Número",left=tel_left[0]*cm,top=tel_top),
Label(text="Tipo",left=tel_left[1]*cm,top=tel_top),
Label(text="Nota",left=tel_left[2]*cm,top=tel_top),
],
borders = {'bottom': True},
),
band_detail = ReportBand(
default_style = {'fontName': 'Helvetica', 'fontSize':11},
height=0.5*cm,
elements= [
ObjectValue(attribute_name='__unicode__',left=tel_left[0]*cm),
ObjectValue(attribute_name='tipo',left=tel_left[1]*cm,
get_value = lambda instance:
{'F':'Fixo','M':u'Móvel','X':'Fax','I':'Indefinido'}[instance.tipo],
),
ObjectValue(attribute_name='nota',left=tel_left[2]*cm),
],
borders = {'all':True},
),
),
#Contatos
SubReport(
queryset_string = '%(object)s.contatos.all()',
band_header = ReportBand(
default_style = {'fontName': 'Helvetica', 'fontSize':12 },
height=2.5*cm,
elements = [
Label(
text="Contato(s)",
style = {'fontSize':14,'alignment': TA_CENTER},
width=BAND_WIDTH,
top=1*cm,
),
Label(text="Nome",left=cont_left[0]*cm,top=cont_top),
Label(text="Nota",left=cont_left[1]*cm,top=cont_top),
Label(text="E-mail",left=cont_left[2]*cm,top=cont_top),
],
borders = {'bottom': True,'top':True},
),
band_detail = ReportBand(
default_style = {'fontName': 'Helvetica', 'fontSize':11},
height=0.5*cm,
elements= [
ObjectValue(attribute_name='nome',left=cont_left[0]*cm),
ObjectValue(attribute_name='nota',left=cont_left[1]*cm),
ObjectValue(attribute_name='email',left=cont_left[2]*cm),
],
borders = {'all':True},
),
),
#Convenios
SubReport( SubReport(
queryset_string = '%(object)s.convenio_set.all()', queryset_string = '%(object)s.convenio_set.all()',
band_header = ReportBand( band_header = ReportBand(
default_style = {'fontName': 'Helvetica', 'fontSize':11}, default_style = {'fontName': 'Helvetica', 'fontSize':12 },
height=2*cm, height=2.5*cm,
elements=[ elements=[
Label( Label(
text="Convênio(s)", text="Convênio(s)",
@ -426,41 +521,13 @@ class InfoCasaLegislativa(ReportDefault):
width=BAND_WIDTH, width=BAND_WIDTH,
top=1*cm, top=1*cm,
), ),
Label( Label(text="Projeto",left=convenio_left[0]*cm,top=convenio_top),
text="Projeto", Label(text="Nº Convenio",left=convenio_left[1]*cm,top=convenio_top),
left=label_left[0]*cm, Label(text="Nº Processo SF",left=convenio_left[2]*cm,top=convenio_top),
top=label_top Label(text="Adesão",left=convenio_left[3]*cm,top=convenio_top),
), Label(text="Convênio",left=convenio_left[4]*cm,top=convenio_top),
Label( Label(text="Equipada",left=convenio_left[5]*cm,top=convenio_top),
text="Nº Convenio", Label(text="Data D.O.",left=convenio_left[6]*cm,top=convenio_top),
left=label_left[1]*cm,
top=label_top
),
Label(
text="Nº Processo SF",
left=label_left[2]*cm,
top=label_top
),
Label(
text="Adesão",
left=label_left[3]*cm,
top=label_top
),
Label(
text="Convênio",
left=label_left[4]*cm,
top=label_top
),
Label(
text="Equipada",
left=label_left[5]*cm,
top=label_top
),
Label(
text="Data D.O.",
left=label_left[6]*cm,
top=label_top
),
], ],
borders = {'bottom': True} borders = {'bottom': True}
), ),
@ -468,47 +535,27 @@ class InfoCasaLegislativa(ReportDefault):
default_style = {'fontName': 'Helvetica', 'fontSize':11}, default_style = {'fontName': 'Helvetica', 'fontSize':11},
height=0.5*cm, height=0.5*cm,
elements=[ elements=[
ObjectValue( ObjectValue(attribute_name='projeto.sigla',left=convenio_left[0]*cm),
attribute_name='projeto.sigla', ObjectValue(attribute_name='num_convenio',left=convenio_left[1]*cm),
left=label_left[0]*cm ObjectValue(attribute_name='num_processo_sf',left=convenio_left[2]*cm),
), ObjectValue(attribute_name='data_adesao',left=convenio_left[3]*cm,
ObjectValue(
attribute_name='num_convenio',
left=label_left[1]*cm
),
ObjectValue(
attribute_name='num_processo_sf',
left=label_left[2]*cm
),
ObjectValue(
attribute_name='data_adesao',
left=label_left[3]*cm,
get_value=lambda instance: get_value=lambda instance:
instance.data_adesao.strftime('%d/%m/%Y') if instance.data_adesao != None else '-' instance.data_adesao.strftime('%d/%m/%Y') if instance.data_adesao != None else '-'
), ),
ObjectValue( ObjectValue(attribute_name='data_retorno_assinatura',left=convenio_left[4]*cm,
attribute_name='data_retorno_assinatura',
left=label_left[4]*cm,
get_value=lambda instance: get_value=lambda instance:
instance.data_retorno_assinatura.strftime('%d/%m/%Y') if instance.data_retorno_assinatura != None else '-' instance.data_retorno_assinatura.strftime('%d/%m/%Y') if instance.data_retorno_assinatura != None else '-'
), ),
ObjectValue( ObjectValue(attribute_name='data_termo_aceite',left=convenio_left[5]*cm,
attribute_name='data_termo_aceite',
left=label_left[5]*cm,
get_value=lambda instance: get_value=lambda instance:
instance.data_termo_aceite.strftime('%d/%m/%Y') if instance.data_termo_aceite != None else '-' instance.data_termo_aceite.strftime('%d/%m/%Y') if instance.data_termo_aceite != None else '-'
), ),
ObjectValue( ObjectValue(attribute_name='data_pub_diario',left=convenio_left[6]*cm,
attribute_name='data_pub_diario',
left=label_left[6]*cm,
get_value=lambda instance: get_value=lambda instance:
instance.data_pub_diario.strftime('%d/%m/%Y') if instance.data_pub_diario != None else '-' instance.data_pub_diario.strftime('%d/%m/%Y') if instance.data_pub_diario != None else '-'
), ),
], ],
#borders={'left': True, 'right': True}, borders = {'all':True},
),
band_footer = ReportBand(
#height=0.5*cm,
), ),
) )
] ]

62
sigi/apps/casas/views.py

@ -17,17 +17,20 @@ from sigi.apps.casas.reports import string_to_cm
from reportlab.lib.units import cm from reportlab.lib.units import cm
def labels_report(request, id=None): def labels_report(request, id=None,queryset=None):
""" TODO: adicionar suporte para resultado de pesquisa do admin. """ TODO: adicionar suporte para resultado de pesquisa do admin.
""" """
qs = CasaLegislativa.objects.all() if queryset:
if id: qs = queryset
qs = qs.filter(pk=id) else:
elif request.GET: qs = CasaLegislativa.objects.all()
kwargs = {} if id:
for k, v in request.GET.iteritems(): qs = qs.filter(pk=id)
kwargs[str(k)] = v elif request.GET:
qs = qs.filter(**kwargs) kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
casasNormais = [] casasNormais = []
@ -151,16 +154,45 @@ def report(request, id=None):
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return response return response
def casa_info(request,id=None): def casa_info(request,id=None,queryset=None):
qs = CasaLegislativa.objects.all() if queryset:
if id: qs = queryset
qs = qs.filter(pk=id)
else: else:
qs = CasaLegislativa.objects.all()
if id:
qs = qs.filter(pk=id)
elif request.GET:
kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
report = InfoCasaLegislativa(queryset=qs)
report.generate_by(PDFGenerator, filename=response) # Gera um relatorio para cada casa e concatena os relatorios
cont = 0
canvas = None
quant = qs.count()
if quant > 1:
for i in qs:
cont += 1
#queryset deve ser uma lista
lista = (i,)
if cont == 1:
report = InfoCasaLegislativa(queryset=lista)
canvas = report.generate_by(PDFGenerator, return_canvas=True,filename=response,)
else:
report = InfoCasaLegislativa(queryset=lista)
if cont == quant:
report.generate_by(PDFGenerator, canvas=canvas)
else:
canvas = report.generate_by(PDFGenerator, canvas=canvas, return_canvas=True)
else:
report = InfoCasaLegislativa(queryset=qs)
report.generate_by(PDFGenerator,filename=response)
return response return response
def casas_sem_convenio_report(request): def casas_sem_convenio_report(request):

Loading…
Cancel
Save