diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index 856c52f..6ca42b6 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -16,6 +16,8 @@ class TelefonesInline(generic.GenericTabularInline): class CasaLegislativaAdmin(admin.ModelAdmin): form = CasaLegislativaForm + change_form_template = 'casas/change_form.html' + change_list_template = 'casas/change_list.html' inlines = (TelefonesInline, ContatosInline) list_display = ('nome', 'email', 'pagina_web', 'municipio') list_display_links = ('nome',) @@ -37,4 +39,10 @@ class CasaLegislativaAdmin(admin.ModelAdmin): 'cep', 'municipio__nome', 'municipio__uf__nome', 'municipio__codigo_ibge', 'pagina_web', 'observacoes') + def changelist_view(self, request, extra_context=None): + return super(CasaLegislativaAdmin, self).changelist_view( + request, + extra_context={'query_str': '?' + request.META['QUERY_STRING']} + ) + admin.site.register(CasaLegislativa, CasaLegislativaAdmin) diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index aec461e..c32ee4d 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from django.db import models from django.contrib.contenttypes import generic -from sigi.apps.mesas.models import MesaDiretora +from sigi.apps.mesas.models import MesaDiretora, MembroMesaDiretora class CasaLegislativa(models.Model): CASA_CHOICES = ( @@ -64,7 +64,12 @@ class CasaLegislativa(models.Model): def __unicode__(self): return self.nome - def get_presidente(self): - mesa = MesaDiretora.objects.get(casa_legislativa=self) - membro = mesa.membromesadiretora_set.get(cargo__descricao__iexact='presidente') - return membro.parlamentar + def get_presidente_nome(self): + try: + mesa = MesaDiretora.objects.get(casa_legislativa=self) + membro = mesa.membromesadiretora_set.get( + cargo__descricao__iexact='presidente' + ) + except (MesaDiretora.DoesNotExist, MembroMesaDiretora.DoesNotExist): + return '' + return membro.parlamentar.nome_completo diff --git a/sigi/apps/casas/reports.py b/sigi/apps/casas/reports.py new file mode 100644 index 0000000..c016f0e --- /dev/null +++ b/sigi/apps/casas/reports.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +import reporting +from reportlab.lib.units import cm +from geraldo import Report, ReportBand, Label, ObjectValue +from sigi.apps.casas.models import CasaLegislativa + +class CasasLegislativasLabels(Report): + """ + Usage example:: + + >>> from geraldo.generators import PDFGenerator + >>> queryset = CasaLegislativa.objects.filter(municipio__uf__sigla='MG') + >>> report = LabelsReport(queryset) + >>> report.generate_by(PDFGenerator, filename='./inline-detail-report.pdf') + + """ + + class band_detail(ReportBand): + width = 9.40*cm + height = 4.60*cm + + # With this attribute as True, the band will try to align in + # the same line. + display_inline = True + + elements = [ + Label(text='A Sua ExcelĂȘncia o(a) Senhor(a)', top=0, left=0), + ObjectValue( + attribute_name='get_presidente_nome', + top=0.5*cm, left=0, width=9.00*cm, + get_value=lambda obj: obj.get_presidente_nome(), + ), + ObjectValue(attribute_name='nome', top=1.0*cm, left=0, width=9.00*cm), + ObjectValue(attribute_name='logradouro', top=1.5*cm, left=0, width=9.00*cm), + ObjectValue(attribute_name='bairro', top=2*cm, left=0, width=9.00*cm), + ObjectValue(attribute_name='municipio', top=2.5*cm, left=0, width=9.00*cm), + ObjectValue(attribute_name='cep', top=3*cm, left=0, width=9.00*cm), + ] + +reporting.site.register(CasasLegislativasLabels, CasaLegislativa, 'etiquetas') diff --git a/sigi/apps/casas/templates/casas/change_form.html b/sigi/apps/casas/templates/casas/change_form.html new file mode 100644 index 0000000..0e9e0dd --- /dev/null +++ b/sigi/apps/casas/templates/casas/change_form.html @@ -0,0 +1,12 @@ +{% extends "admin/change_form.html" %} +{% load i18n reporting_tags %} + +{% block object-tools %} +{% if change %}{% if not is_popup %} +