Browse Source

Adicionando relatorio sobre dados estatisticos por regiao

0.3
Camilo Carlos (Estagiario) 15 years ago
parent
commit
5d7d0f5b52
  1. 46
      sigi/apps/convenios/reports.py
  2. 36
      sigi/apps/convenios/views.py

46
sigi/apps/convenios/reports.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from geraldo import Report, ReportBand, ObjectValue, DetailBand, Label from geraldo import Report, ReportBand, ObjectValue, DetailBand, Label, FIELD_ACTION_SUM, FIELD_ACTION_COUNT
from reportlab.lib.units import cm from reportlab.lib.units import cm
class CasasAderidasReport(object): class CasasAderidasReport(object):
pass pass
@ -40,3 +40,47 @@ class ConvenioReport(Report):
ObjectValue(attribute_name='data_adesao', left=10*cm) ObjectValue(attribute_name='data_adesao', left=10*cm)
] ]
border = {'bottom': True} border = {'bottom': True}
class ConvenioReportRegiao(Report):
title = u'Relatório dos Convênios por Região'
author = u'Interlegis'
class band_page_header(ReportBand):
elements = [
Label(
text="Região", left=0*cm
),
Label(
text="Quantidade Casas", left=3*cm,
),
Label(
text="Quantidade Casas Conveniadas", left=6*cm
),
Label(
text="Porcentagem Casas Conveniadas", left=15*cm
),
]
class band_detail(DetailBand):
height = 0.5*cm
elements=[
ObjectValue(attribute_name='regiao', left=0*cm, ),
ObjectValue(attribute_name='casas', left=3*cm,),
ObjectValue(attribute_name='casas_conveniadas', left=6*cm),
ObjectValue(attribute_name='porc_casas_conveniadas', left=15*cm),
]
border = {'bottom': True}
class band_summary(ReportBand):
elements = [
Label(text="Total", top=0.1*cm, left=0),
ObjectValue(attribute_name='casas', action=FIELD_ACTION_SUM, left=3*cm, top=0.1*cm),
ObjectValue(attribute_name='casas_conveniadas', left=6*cm, action=FIELD_ACTION_SUM),
]
borders = {'top':True}
child_bands = [
ReportBand(
height = 0.6*cm,
elements = [
Label(text="Total",),
ObjectValue(attribute_name='casas', action=FIELD_ACTION_COUNT,)
]
),
]

36
sigi/apps/convenios/views.py

@ -1,7 +1,9 @@
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from geraldo.generators import PDFGenerator from geraldo.generators import PDFGenerator
from sigi.apps.convenios.models import Convenio from sigi.apps.convenios.models import Convenio
from sigi.apps.convenios.reports import ConvenioReport from sigi.apps.convenios.reports import ConvenioReport, ConvenioReportRegiao
from sigi.apps.casas.models import CasaLegislativa
def report(request, id=None): def report(request, id=None):
qs = Convenio.objects.all() qs = Convenio.objects.all()
@ -25,3 +27,35 @@ def report(request, id=None):
report = ConvenioReport(queryset=qs) report = ConvenioReport(queryset=qs)
report.generate_by(PDFGenerator, filename=response) report.generate_by(PDFGenerator, filename=response)
return response return response
class Relatorios(object):
def __init__(self, regiao, casas, casas_conveniadas):
self.regiao = regiao
self.casas = casas
self.casas_conveniadas = casas_conveniadas
if(casas_conveniadas!=0):
self.porc_casas_conveniadas = float(casas_conveniadas)/float(casas)*100
else:
self.porc_casas_conveniadas = 0
def reportRegiao(request):
REGIAO_CHOICES = (
('SL', 'Sul'),
('SD', 'Sudeste'),
('CO', 'Centro-Oeste'),
('NE', 'Nordeste'),
('NO', 'Norte'),
)
relatorio = []
for casa in REGIAO_CHOICES:
casasSD = CasaLegislativa.objects.filter(municipio__uf__regiao=casa[0])
casasConvSD = CasaLegislativa.objects.filter(convenio__casa_legislativa__municipio__uf__regiao=casa[0]).distinct()
relatorio.append(Relatorios(casa[1], casasSD.count(),
casasConvSD.count()))
response = HttpResponse(mimetype='application/pdf')
relatorio = ConvenioReportRegiao(queryset=relatorio)
relatorio.generate_by(PDFGenerator, filename=response)
return response

Loading…
Cancel
Save