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. 19
      sigi/apps/casas/admin.py
  2. 251
      sigi/apps/casas/reports.py
  3. 64
      sigi/apps/casas/views.py

19
sigi/apps/casas/admin.py

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

251
sigi/apps/casas/reports.py

@ -76,7 +76,7 @@ class CasasLegislativasLabels(Report):
top=1*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
attribute_name='parlamentar',
attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
@ -111,7 +111,7 @@ class CasasLabelsNomeMaior(CasasLegislativasLabels):
top=1*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
attribute_name='parlamentar',
attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
@ -146,7 +146,7 @@ class CasasLabelsEnderecoMaior(CasasLegislativasLabels):
top=1*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
attribute_name='parlamentar',
attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
@ -181,7 +181,7 @@ class CasasLabelsNomeMaiorEnderecoMaior(CasasLegislativasLabels):
top=1*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
attribute_name='parlamentar',
attribute_name='presidente',
top=1.5*cm, left=0.5*cm, width=9.4*cm,
),
ObjectValue(
@ -213,6 +213,7 @@ class CasasLabelsNomeMaiorEnderecoMaior(CasasLegislativasLabels):
class CasasLegislativasReport(ReportDefault):
title = u'Relatório de Casas Legislativas'
height = 80*cm
class band_page_header(ReportDefault.band_page_header):
@ -263,7 +264,7 @@ class CasasLegislativasReport(ReportDefault):
left=label_left[1]*cm,
),
ObjectValue(
attribute_name='parlamentar',
attribute_name='presidente',
left=label_left[2]*cm,
),
ObjectValue(
@ -289,28 +290,33 @@ class CasasLegislativasReport(ReportDefault):
class CasasSemConvenioReport(CasasLegislativasReport):
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):
posicao_left = [
0,1.3, #Tipo
0,1.8, #Regiao
5.5,6.8, #U.F.
12,13.3, #Tipo
5.5,6.8, #U.F.
0,2.3, #Municipio
0,2.8, #Logradouro
0,1.6, #Bairro
0,1.3, #CEP
0,1.6, #CNPJ
0,2.3, #Telefone
0,2.7, #Presidente
]
posicao_top = [
0.5, #Regiao
0.5, #U.F.
0.5, #Tipo
1.3, #Municipio
2.1, #Logradouro
2.9, #Bairro
3.7, #CEP
4.5, #Presidente
1.3, #Regiao
1.3, #U.F.
2.1, #Municipio
2.9, #Logradouro
3.7, #Bairro
4.5, #CEP
5.3, #CNPJ
6.1, #Telefone
6.9, #Presidente
]
height=30*cm
@ -320,42 +326,40 @@ class InfoCasaLegislativa(ReportDefault):
elements = [
# Linha 1
Label(
text="Região: ",
text="Tipo: ",
left=posicao_left[0]*cm,
top=posicao_top[0]*cm,
),
),
ObjectValue(
attribute_name='municipio.uf.regiao',
attribute_name='tipo.nome',
left=posicao_left[1]*cm,
top=posicao_top[0]*cm,
get_value=lambda instance:
{'SL': 'Sul','SD': 'Sudeste','CO': 'Centro-Oeste','NE': 'Nordeste','NO': 'Norte',}
[instance.municipio.uf.regiao]
width=6*cm,
),
Label(
text="U.F.: ",
text="Região: ",
left=posicao_left[2]*cm,
top=posicao_top[1]*cm,
),
),
ObjectValue(
attribute_name='municipio.uf',
attribute_name='municipio.uf.regiao',
left=posicao_left[3]*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(
text="Tipo: ",
text="U.F.: ",
left=posicao_left[4]*cm,
top=posicao_top[2]*cm,
),
ObjectValue(
attribute_name='tipo.nome',
attribute_name='municipio.uf',
left=posicao_left[5]*cm,
top=posicao_top[2]*cm,
width=6*cm,
),
# Linha 2
),
Label(
text="Município: ",
left=posicao_left[6]*cm,
@ -400,25 +404,116 @@ class InfoCasaLegislativa(ReportDefault):
top=posicao_top[6]*cm,
),
Label(
text="Presidente: ",
text="CNPJ: ",
left=posicao_left[14]*cm,
top=posicao_top[7]*cm,
),
ObjectValue(
attribute_name='parlamentar',
attribute_name='cnpj',
left=posicao_left[15]*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,
),
]
label_top = 1.5*cm
label_left = [0,1.5,4,8,10.5,13,15.5,18]
]
# Telefones
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 = [
# Telefones
SubReport(
queryset_string = '%(object)s.convenio_set.all()',
queryset_string = '%(object)s.telefones.all()',
band_header = ReportBand(
default_style = {'fontName': 'Helvetica', 'fontSize':11},
height=2*cm,
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(
queryset_string = '%(object)s.convenio_set.all()',
band_header = ReportBand(
default_style = {'fontName': 'Helvetica', 'fontSize':12 },
height=2.5*cm,
elements=[
Label(
text="Convênio(s)",
@ -426,41 +521,13 @@ class InfoCasaLegislativa(ReportDefault):
width=BAND_WIDTH,
top=1*cm,
),
Label(
text="Projeto",
left=label_left[0]*cm,
top=label_top
),
Label(
text="Nº Convenio",
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
),
Label(text="Projeto",left=convenio_left[0]*cm,top=convenio_top),
Label(text="Nº Convenio",left=convenio_left[1]*cm,top=convenio_top),
Label(text="Nº Processo SF",left=convenio_left[2]*cm,top=convenio_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(text="Equipada",left=convenio_left[5]*cm,top=convenio_top),
Label(text="Data D.O.",left=convenio_left[6]*cm,top=convenio_top),
],
borders = {'bottom': True}
),
@ -468,48 +535,28 @@ class InfoCasaLegislativa(ReportDefault):
default_style = {'fontName': 'Helvetica', 'fontSize':11},
height=0.5*cm,
elements=[
ObjectValue(
attribute_name='projeto.sigla',
left=label_left[0]*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,
ObjectValue(attribute_name='projeto.sigla',left=convenio_left[0]*cm),
ObjectValue(attribute_name='num_convenio',left=convenio_left[1]*cm),
ObjectValue(attribute_name='num_processo_sf',left=convenio_left[2]*cm),
ObjectValue(attribute_name='data_adesao',left=convenio_left[3]*cm,
get_value=lambda instance:
instance.data_adesao.strftime('%d/%m/%Y') if instance.data_adesao != None else '-'
),
ObjectValue(
attribute_name='data_retorno_assinatura',
left=label_left[4]*cm,
ObjectValue(attribute_name='data_retorno_assinatura',left=convenio_left[4]*cm,
get_value=lambda instance:
instance.data_retorno_assinatura.strftime('%d/%m/%Y') if instance.data_retorno_assinatura != None else '-'
),
ObjectValue(
attribute_name='data_termo_aceite',
left=label_left[5]*cm,
ObjectValue(attribute_name='data_termo_aceite',left=convenio_left[5]*cm,
get_value=lambda instance:
instance.data_termo_aceite.strftime('%d/%m/%Y') if instance.data_termo_aceite != None else '-'
),
ObjectValue(
attribute_name='data_pub_diario',
left=label_left[6]*cm,
ObjectValue(attribute_name='data_pub_diario',left=convenio_left[6]*cm,
get_value=lambda instance:
instance.data_pub_diario.strftime('%d/%m/%Y') if instance.data_pub_diario != None else '-'
),
],
#borders={'left': True, 'right': True},
),
band_footer = ReportBand(
#height=0.5*cm,
),
borders = {'all':True},
),
)
]

64
sigi/apps/casas/views.py

@ -17,17 +17,20 @@ from sigi.apps.casas.reports import string_to_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.
"""
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 queryset:
qs = queryset
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)
casasNormais = []
@ -151,16 +154,45 @@ def report(request, id=None):
report.generate_by(PDFGenerator, filename=response)
return response
def casa_info(request,id=None):
qs = CasaLegislativa.objects.all()
if id:
qs = qs.filter(pk=id)
def casa_info(request,id=None,queryset=None):
if queryset:
qs = queryset
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('../')
response = HttpResponse(mimetype='application/pdf')
report = InfoCasaLegislativa(queryset=qs)
report.generate_by(PDFGenerator, filename=response)
response = HttpResponse(mimetype='application/pdf')
# 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
def casas_sem_convenio_report(request):

Loading…
Cancel
Save