diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index 0564a6d..f8a717b 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -8,7 +8,7 @@ from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, A 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 +from sigi.apps.casas.views import casa_info, labels_report, export_csv, labels_report_sem_presidente from sigi.apps.utils import queryset_ascii class ContatosInline(generic.GenericTabularInline): @@ -29,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','relatorio_completo'] + actions = ['etiqueta','relatorio','relatorio_csv','relatorio_completo','etiqueta_sem_presidente'] inlines = (TelefonesInline, ContatosInline, ConveniosInline) list_display = ('nome','municipio','presidente','logradouro') list_display_links = ('nome',) @@ -65,17 +65,27 @@ class CasaLegislativaAdmin(admin.ModelAdmin): return labels_report(request,queryset=queryset) etiqueta.short_description = "Gerar etiqueta(s) da(s) casa(s) selecionada(s)" + def etiqueta_sem_presidente(modelAdmin,request,queryset): + response = HttpResponse(mimetype='application/pdf') + return labels_report_sem_presidente(request,queryset=queryset) + etiqueta_sem_presidente.short_description = "Gerar etiqueta(s) sem presidente 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 resumido da(s) casa(s) selecionada(s)" + relatorio.short_description = u"Exportar a(s) casa(s) selecionada(s) para PDF" 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 relatorio_csv(modelAdmin,request,queryset): + response = HttpResponse(mimetype='text/csv') + return export_csv(request) + relatorio_csv.short_description = u"Exportar casa(s) selecionada(s) para CSV" def get_actions(self, request): actions = super(CasaLegislativaAdmin, self).get_actions(request) diff --git a/sigi/apps/casas/reports.py b/sigi/apps/casas/reports.py index 424908d..b727e85 100644 --- a/sigi/apps/casas/reports.py +++ b/sigi/apps/casas/reports.py @@ -70,7 +70,45 @@ class CasasLegislativasLabels(Report): default_style = {'fontName': 'Helvetica', 'fontSize': 11} + elements = [ + Label( + text='A Sua Excelência o(a) Senhor(a)', + top=1*cm, left=0.5*cm, width=9.4*cm, + ), + ObjectValue( + attribute_name='presidente', + top=1.5*cm, left=0.5*cm, width=9.4*cm, + ), + ObjectValue( + attribute_name='tipo', + top=2*cm, left=0.5*cm, width=9.4*cm, + get_value=lambda instance: + "Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2] + ), + ObjectValue( + attribute_name='nome', + top=2.5*cm, left=0.5*cm, width=9.4*cm, + get_value=lambda instance: + instance.municipio.uf.nome + if instance.tipo.nome == u'Assembléia Legislativa' + else instance.municipio.nome + + ), + ManyElements( + ObjectValue, + count=4, + attribute_name=('logradouro','bairro','municipio','cep'), + start_top=3*cm, height=0.5*cm, left=0.5*cm, width=9.4*cm, + ), + + ] + + + +class CasasLegislativasLabelsSemPresidente(CasasLegislativasLabels): + + class band_detail(CasasLegislativasLabels.band_detail): elements = [ Label( text='A Sua Excelência o(a) Senhor(a)', @@ -80,7 +118,7 @@ class CasasLegislativasLabels(Report): attribute_name='tipo', top=1.5*cm, left=0.5*cm, width=9.4*cm, get_value=lambda instance: - "Presidente da " + instance.tipo.nome + " de " + "Presidente da " + instance.tipo.nome +" " +instance.nome.split()[2] ), ObjectValue( attribute_name='nome', @@ -99,6 +137,7 @@ class CasasLegislativasLabels(Report): ), ] + class CasasLegislativasReport(ReportDefault): title = u'Relatório de Casas Legislativas' diff --git a/sigi/apps/casas/templates/casas/change_list.html b/sigi/apps/casas/templates/casas/change_list.html index 92cfc75..be645e1 100644 --- a/sigi/apps/casas/templates/casas/change_list.html +++ b/sigi/apps/casas/templates/casas/change_list.html @@ -1,9 +1,67 @@ {% extends "admin/change_list.html" %} {% load adminmedia admin_list i18n reporting_tags %} +{% block extrastyle %} + {{ block.super }} + {% include "jquery/tabs_style.html" %} +{% endblock %} + {% block object-tools %} {% if has_add_permission %} -