Browse Source

Criando relatorio de casas

diagnosticos
Starlone (Estagiario) 15 years ago
parent
commit
ca7d234588
  1. 12
      sigi/apps/casas/admin.py
  2. 87
      sigi/apps/casas/reports.py
  3. 1
      sigi/apps/casas/templates/casas/change_list.html
  4. 20
      sigi/apps/casas/views.py

12
sigi/apps/casas/admin.py

@ -6,7 +6,7 @@ from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.contatos.models import Contato, Telefone from sigi.apps.contatos.models import Contato, Telefone
from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from sigi.apps.casas.reports import CasasLegislativasLabels from sigi.apps.casas.reports import CasasLegislativasLabels, CasasLegislativasReport
from geraldo.generators import PDFGenerator from geraldo.generators import PDFGenerator
class ContatosInline(generic.GenericTabularInline): class ContatosInline(generic.GenericTabularInline):
@ -26,11 +26,12 @@ 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 = ['delete_selected','etiqueta'] actions = ['delete_selected','etiqueta','relatorio']
inlines = (TelefonesInline, ContatosInline, ConveniosInline) inlines = (TelefonesInline, ContatosInline, ConveniosInline)
list_display = ('nome', 'email', 'pagina_web', 'municipio') list_display = ('nome', 'email', 'pagina_web', 'municipio')
list_display_links = ('nome',) list_display_links = ('nome',)
list_filter = ('tipo', 'municipio') list_filter = ('tipo', 'municipio')
ordering = ('municipio__uf','nome')
fieldsets = ( fieldsets = (
(None, { (None, {
'fields': ('nome', 'sigla', 'tipo', 'cnpj', 'observacoes', 'fields': ('nome', 'sigla', 'tipo', 'cnpj', 'observacoes',
@ -62,4 +63,11 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
return 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):
response = HttpResponse(mimetype='application/pdf')
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)"
admin.site.register(CasaLegislativa, CasaLegislativaAdmin) admin.site.register(CasaLegislativa, CasaLegislativaAdmin)

87
sigi/apps/casas/reports.py

@ -1,7 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from reportlab.lib.pagesizes import A4 from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm from reportlab.lib.units import cm
from geraldo import Report, DetailBand, Label, ObjectValue, ManyElements from geraldo import Report, DetailBand, Label, ObjectValue, ManyElements, \
ReportGroup, ReportBand
from sigi.apps.relatorios.reports import ReportDefault
class CasasLegislativasLabels(Report): class CasasLegislativasLabels(Report):
""" """
@ -44,3 +47,85 @@ class CasasLegislativasLabels(Report):
start_top=1.5*cm, height=0.5*cm, left=1*cm, width=9.4*cm, start_top=1.5*cm, height=0.5*cm, left=1*cm, width=9.4*cm,
), ),
] ]
class CasasLegislativasReport(ReportDefault):
title = u'Relatório de Casas Legislativas'
class band_page_header(ReportDefault.band_page_header):
label_top = ReportDefault.band_page_header.label_top
label_left = [0.3,1,5.5,6.5,12]
elements = list(ReportDefault.band_page_header.elements)
elements += [
Label(
text="UF",
left=label_left[0]*cm,
top=label_top
),
Label(
text="Municipio",
left=label_left[1]*cm,
top=label_top
),
Label(
text="Tipo",
left=label_left[2]*cm,
top=label_top
),
Label(
text="Presidente",
left=label_left[3]*cm,
top=label_top
),
Label(
text="Logradouro",
left=label_left[4]*cm,
top=label_top
),
]
class band_page_footer(ReportDefault.band_page_footer):
pass
class band_detail(ReportDefault.band_detail):
label_left = [0.3,1,5.5,6.5,12]
elements=[
ObjectValue(
attribute_name='municipio.uf.sigla',
left=label_left[0]*cm
),
ObjectValue(
attribute_name='municipio.nome',
left=label_left[1]*cm
),
ObjectValue(
attribute_name='tipo',
left=label_left[2]*cm
),
ObjectValue(
attribute_name='parlamentar',
left=label_left[3]*cm
),
ObjectValue(
attribute_name='logradouro',
left=label_left[4]*cm,
),
]
groups = [
ReportGroup(attribute_name='municipio.uf',
band_header=ReportBand(
height=0.7*cm,
elements= [
ObjectValue(attribute_name='municipio.uf')
],
borders={'top': True},
)
)
]

1
sigi/apps/casas/templates/casas/change_list.html

@ -4,6 +4,7 @@
{% block object-tools %} {% block object-tools %}
{% if has_add_permission %} {% if has_add_permission %}
<ul class="object-tools"> <ul class="object-tools">
<li><a href="reports/{{query_str}}">Relatório</a> </li>
<li><a href="labels/{{ query_str }}">Gerar etiquetas</a></li> <li><a href="labels/{{ query_str }}">Gerar etiquetas</a></li>
<li> <li>
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink"> <a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">

20
sigi/apps/casas/views.py

@ -2,6 +2,8 @@ from django.http import HttpResponse, HttpResponseRedirect
from geraldo.generators import PDFGenerator from geraldo.generators import PDFGenerator
from sigi.apps.casas.models import CasaLegislativa from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.casas.reports import CasasLegislativasLabels from sigi.apps.casas.reports import CasasLegislativasLabels
from sigi.apps.casas.reports import CasasLegislativasReport
def labels_report(request, id=None): def labels_report(request, id=None):
""" TODO: adicionar suporte para resultado de pesquisa do admin. """ TODO: adicionar suporte para resultado de pesquisa do admin.
@ -20,3 +22,21 @@ def labels_report(request, id=None):
report = CasasLegislativasLabels(queryset=qs) report = CasasLegislativasLabels(queryset=qs)
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return response return response
def report(request, id=None):
qs = CasaLegislativa.objects.all().order_by('municipio__uf','nome')
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('../')
#qs.order_by('municipio__uf','nome')
response = HttpResponse(mimetype='application/pdf')
report = CasasLegislativasReport(queryset=qs)
report.generate_by(PDFGenerator, filename=response)
return response

Loading…
Cancel
Save