diff --git a/sigi/apps/convenios/admin.py b/sigi/apps/convenios/admin.py index 5942e06..1299ab3 100644 --- a/sigi/apps/convenios/admin.py +++ b/sigi/apps/convenios/admin.py @@ -2,6 +2,7 @@ from django.contrib import admin from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo from sigi.apps.servicos.models import Servico +from django.http import HttpResponseRedirect class AnexosInline(admin.TabularInline): model = Anexo @@ -33,17 +34,29 @@ class ConvenioAdmin(admin.ModelAdmin): 'data_devolucao_via', 'data_postagem_correio')} ), ) + actions = ['delete_selected', 'relatorio'] inlines = (AnexosInline, EquipamentoPrevistoInline) list_display = ('id', 'casa_legislativa', - 'num_processo_sf', 'data_adesao') + 'num_processo_sf', 'data_adesao', 'projeto') list_filter = ('data_adesao', 'data_retorno_assinatura', 'data_termo_aceite', 'data_devolucao_via', - 'data_postagem_correio') + 'data_postagem_correio', 'projeto') ordering = ('-id',) raw_id_fields = ('casa_legislativa',) search_fields = ('id', 'casa_legislativa__nome', 'num_processo_sf', 'casa_legislativa__municipio__nome', 'casa_legislativa__municipio__uf__nome') + def changelist_view(self, request, extra_context=None): + return super(ConvenioAdmin, self).changelist_view( + request, + extra_context={'query_str': '?' + request.META['QUERY_STRING']} + ) + def relatorio(modeladmin, request, queryset): + selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME) + print selected + return HttpResponseRedirect("reports/?ids=%s"%(",".join(selected))) + relatorio.short_description = 'Selecione para gerar relatorio' + class EquipamentoPrevistoAdmin(admin.ModelAdmin): list_display = ('convenio', 'equipamento', 'quantidade') @@ -56,4 +69,3 @@ class EquipamentoPrevistoAdmin(admin.ModelAdmin): admin.site.register(Projeto) admin.site.register(Convenio, ConvenioAdmin) admin.site.register(EquipamentoPrevisto, EquipamentoPrevistoAdmin) -admin.site.register(Anexo, AnexoAdmin) diff --git a/sigi/apps/convenios/reports.py b/sigi/apps/convenios/reports.py index 86eca5d..40cb180 100644 --- a/sigi/apps/convenios/reports.py +++ b/sigi/apps/convenios/reports.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 -*- +from geraldo import Report, ReportBand, ObjectValue, DetailBand, Label +from reportlab.lib.units import cm class CasasAderidasReport(object): pass @@ -9,3 +12,31 @@ class CasasComEquipamentosReport(object): class SemEquipamentosReport(object): pass +class ConvenioReport(Report): + title = u'Relatórios dos Convênios' + author = u'Interlegis' + class band_page_header(ReportBand): + elements = [ + Label( + text="ID", left=0.5*cm + ), + Label( + text="Nº Processo", left=3*cm + ), + Label( + text="Nome", left=5*cm + ), + Label( + text="Data Adesão", left=10*cm + ), + ] + #borders = {'bottom': True} + class band_detail(DetailBand): +# height = 0.5*cm + elements=[ + ObjectValue(attribute_name='id', left=0.5*cm), + ObjectValue(attribute_name='num_processo_sf', left=3*cm), + ObjectValue(attribute_name='casa_legislativa', left=5*cm), + ObjectValue(attribute_name='data_adesao', left=10*cm) + ] + border = {'bottom': True} diff --git a/sigi/apps/convenios/views.py b/sigi/apps/convenios/views.py new file mode 100644 index 0000000..50d88b6 --- /dev/null +++ b/sigi/apps/convenios/views.py @@ -0,0 +1,25 @@ +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 + +def report(request, id=None): + qs = Convenio.objects.all() + if id: + qs = qs.filter(pk=id) + elif request.GET: #Se tiver algum parametro de pesquisa + kwargs = {} + for k, v in request.GET.iteritems(): + kwargs[str(k)] = v + if(str(k)=='ids'): + break + qs = qs.filter(**kwargs) + if kwargs['ids']: + query = 'id IN ('+ kwargs['ids'].__str__()+')' + qs = Convenio.objects.extra(where=[query]) + if not qs: + return HttpResponseRedirect('../') + response = HttpResponse(mimetype='application/pdf') + report = ConvenioReport(queryset=qs) + report.generate_by(PDFGenerator, filename=response) + return response diff --git a/sigi/urls.py b/sigi/urls.py index 6eb1965..a4a82d0 100644 --- a/sigi/urls.py +++ b/sigi/urls.py @@ -8,11 +8,14 @@ import sigi.admin.filterspecs urlpatterns = patterns( '', - # reports + # reports labels (r'^casas/casalegislativa/labels/', 'sigi.apps.casas.views.labels_report'), (r'^casas/casalegislativa/(?P\w+)/labels/', 'sigi.apps.casas.views.labels_report'), + # reports + (r'^convenios/convenio/reports/', + 'sigi.apps.convenios.views.report'), # automatic interface based on admin (r'^(.*)', sites.default.root),