diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index 353ddda..07f1a0b 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -32,7 +32,7 @@ class CasaLegislativaAdmin(admin.ModelAdmin): list_display = ('nome','municipio','parlamentar','logradouro') list_display_links = ('nome',) list_filter = ('tipo', 'municipio') - ordering = ('municipio__uf','nome') + ordering = ('nome','municipio__uf') fieldsets = ( (None, { 'fields': ('nome', 'sigla', 'tipo', 'cnpj', 'observacoes', diff --git a/sigi/apps/casas/reports.py b/sigi/apps/casas/reports.py index 5d46791..29c213a 100644 --- a/sigi/apps/casas/reports.py +++ b/sigi/apps/casas/reports.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm +from reportlab.lib.enums import TA_CENTER, TA_RIGHT from geraldo import Report, DetailBand, Label, ObjectValue, ManyElements, \ - ReportGroup, ReportBand, landscape + ReportGroup, ReportBand, landscape, SubReport, BAND_WIDTH from sigi.apps.relatorios.reports import ReportDefault @@ -294,11 +295,12 @@ class InfoCasaLegislativa(ReportDefault): posicao_left = [ 0,1.8, #Regiao 5.5,6.8, #U.F. - 12,13.3, #Tipo + 12,13.3, #Tipo 0,2.3, #Municipio 0,2.8, #Logradouro - 0,1.6, #Bairro - 0,1.3, #CEP + 0,1.6, #Bairro + 0,1.3, #CEP + 0,2.7, #Presidente ] posicao_top = [ 0.5, #Regiao @@ -308,13 +310,14 @@ class InfoCasaLegislativa(ReportDefault): 2.1, #Logradouro 2.9, #Bairro 3.7, #CEP + 4.5, #Presidente ] - display_inline = True - REGIAO_CHOICES = {'SL': 'Sul','SD': 'Sudeste','CO': 'Centro-Oeste','NE': 'Nordeste','NO': 'Norte',} - default_style = {'fontName': 'Helvetica', 'fontSize':14} - + height=30*cm + display_inline = True + default_style = {'fontName': 'Helvetica', 'fontSize':14} + elements = [ # Linha 1 @@ -396,6 +399,118 @@ class InfoCasaLegislativa(ReportDefault): left=posicao_left[13]*cm, top=posicao_top[6]*cm, ), + Label( + text="Presidente: ", + left=posicao_left[14]*cm, + top=posicao_top[7]*cm, + ), + ObjectValue( + attribute_name='parlamentar', + left=posicao_left[15]*cm, + top=posicao_top[7]*cm, + width=20*cm, + ), + ] + label_top = 1.5*cm + label_left = [0,1.5,4,8,10.5,13,15.5,18] + subreports = [ + SubReport( + queryset_string = '%(object)s.convenio_set.all()', + band_header = ReportBand( + default_style = {'fontName': 'Helvetica', 'fontSize':11}, + height=2*cm, + elements=[ + Label( + text="Convênio(s)", + style = {'fontSize':14,'alignment': TA_CENTER}, + 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 + ), + ], + borders = {'bottom': True} + ), + band_detail = ReportBand( + 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, + 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, + 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, + 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, + 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, + ), + ) + ] - - ] \ No newline at end of file + \ No newline at end of file diff --git a/sigi/apps/convenios/models.py b/sigi/apps/convenios/models.py index 6adc4ef..8d92f29 100644 --- a/sigi/apps/convenios/models.py +++ b/sigi/apps/convenios/models.py @@ -18,6 +18,9 @@ class Convenio(models.Model): ) casa_legislativa.convenio_uf_filter = True casa_legislativa.convenio_cl_tipo_filter = True + projeto = models.ForeignKey( + Projeto + ) num_processo_sf = models.CharField( 'número do processo SF', max_length=11, @@ -33,10 +36,7 @@ class Convenio(models.Model): 'Aderidas', null=True, blank=True, - ) - projeto = models.ForeignKey( - Projeto - ) + ) data_retorno_assinatura = models.DateField( 'Conveniadas', null=True, diff --git a/sigi/apps/convenios/reports.py b/sigi/apps/convenios/reports.py index c2b437d..53fe5b1 100644 --- a/sigi/apps/convenios/reports.py +++ b/sigi/apps/convenios/reports.py @@ -145,31 +145,42 @@ class ConvenioReport(ReportDefault): ] -class ConvenioReportRegiao(Report): - title = u'Relatório dos Convênios por Região' - author = u'Interlegis' - class band_page_header(ReportBand): - elements = [ +class ConvenioReportRegiao(ReportDefault): + title = u'Relatório de Convênios por Região' + + class band_page_header(ReportDefault.band_page_header): + label_top = ReportDefault.band_page_header.label_top + + elements = list(ReportDefault.band_page_header.elements) + + elements += [ Label( - text="Região", left=0*cm + text="Região", left=0*cm, + top=label_top, ), Label( - text="Quantidade Casas", left=3*cm, + text="Casas", left=3*cm, + top=label_top, ), Label( - text="Quantidade Casas Conveniadas", left=6*cm + text="Conveniadas", left=5*cm, + top=label_top, + ), + Label( + text="%", left=7*cm, + top=label_top ), Label( - text="Porcentagem Casas Conveniadas", left=15*cm + text="Não Conveniadas", left=9*cm, + top=label_top, ), ] - class band_detail(DetailBand): - height = 0.5*cm + class band_detail(ReportDefault.band_detail): 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), + ObjectValue(attribute_name='casas_conveniadas', left=5*cm), + ObjectValue(attribute_name='porc_casas_conveniadas', left=7*cm), ] border = {'bottom': True} @@ -180,12 +191,17 @@ class ConvenioReportRegiao(Report): 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,) - ] - ), - ] + #child_bands = [ + # ReportBand( + # height = 0.6*cm, + # elements = [ + # Label(text="Total",), + # ObjectValue(attribute_name='casas', action=FIELD_ACTION_COUNT,) + # ] + # ), + # ] +class ConvenioPorCMReport(ConvenioReport): + title = u'Relatório de Convênios por Câmera Municipal' + +class ConvenioPorALReport(ConvenioReport): + title = u'Relatório de Convênios por Assembléia Legislativa' \ No newline at end of file diff --git a/sigi/apps/convenios/views.py b/sigi/apps/convenios/views.py index c10165e..8c1d671 100644 --- a/sigi/apps/convenios/views.py +++ b/sigi/apps/convenios/views.py @@ -1,7 +1,10 @@ from django.http import HttpResponse, HttpResponseRedirect from geraldo.generators import PDFGenerator from sigi.apps.convenios.models import Convenio -from sigi.apps.convenios.reports import ConvenioReport, ConvenioReportRegiao +from sigi.apps.convenios.reports import ConvenioReport, \ + ConvenioPorCMReport, \ + ConvenioPorALReport, \ + ConvenioReportRegiao from sigi.apps.casas.models import CasaLegislativa @@ -24,7 +27,7 @@ def report_por_cm(request, id=None): if not qs: return HttpResponseRedirect('../') response = HttpResponse(mimetype='application/pdf') - report = ConvenioReport(queryset=qs) + report = ConvenioPorCMReport(queryset=qs) report.generate_by(PDFGenerator, filename=response) return response @@ -47,32 +50,43 @@ def report_por_al(request, id=None): if not qs: return HttpResponseRedirect('../') response = HttpResponse(mimetype='application/pdf') - report = ConvenioReport(queryset=qs) + report = ConvenioPorALReport(queryset=qs) report.generate_by(PDFGenerator, filename=response) return response class Relatorios(object): def __init__(self, regiao, casas, casas_conveniadas): self.regiao = regiao - self.casas = casas - self.casas_conveniadas = casas_conveniadas + self.quant_casas = casas + self.quant_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() + ) + + convenios = Convenio.object.all() + + regioes = [] + conveniosCO.filter(municipio__uf__regiao='CO') + conveniosNO.filter(municipio__uf__regiao='NO') + conveniosNE.filter(municipio__uf__regiao='NE') + conveniosSD.filter(municipio__uf__regiao='SD') + conveniosSL.filter(municipio__uf__regiao='SL') + + for regiao in REGIAO_CHOICES: + + casasSD = CasaLegislativa.objects.filter(municipio__uf__regiao=regiao[0]) + casasConvSD = CasaLegislativa.objects.filter(convenio__casa_legislativa__municipio__uf__regiao=regiao[0]).distinct() relatorio.append(Relatorios(casa[1], casasSD.count(), casasConvSD.count())) diff --git a/sigi/apps/relatorios/reports.py b/sigi/apps/relatorios/reports.py index dc7dc6d..61bd3f2 100644 --- a/sigi/apps/relatorios/reports.py +++ b/sigi/apps/relatorios/reports.py @@ -60,3 +60,4 @@ class ReportDefault(Report): class band_detail(DetailBand): height = 0.5*cm default_style = {'fontName': 'Helvetica', 'fontSize': 8} + auto_expand_height = True diff --git a/sigi/context_processors.py b/sigi/context_processors.py index 19592fb..63b6af1 100644 --- a/sigi/context_processors.py +++ b/sigi/context_processors.py @@ -40,8 +40,8 @@ def charts_data(request): num_casas_conveniadas_regiao = [] for regiao in REGIAO_CHOICES: num_casas_conveniadas_regiao.append( - CasaLegislativa.objects.filter( - convenio__casa_legislativa__municipio__uf__regiao=regiao + casas.filter( + municipio__uf__regiao=regiao ).exclude( convenio__data_retorno_assinatura=None ).distinct().count() @@ -60,8 +60,8 @@ def charts_data(request): if num_regiao_maior\w+)/casa_info/', + 'sigi.apps.casas.views.casa_info'), # reports labels (r'^casas/casalegislativa/labels/', 'sigi.apps.casas.views.labels_report'),