Browse Source

Adicionando primeiros relatórios de convênios

0.3
Camilo Carlos (Estagiario) 15 years ago
parent
commit
9aee20172f
  1. 18
      sigi/apps/convenios/admin.py
  2. 31
      sigi/apps/convenios/reports.py
  3. 25
      sigi/apps/convenios/views.py
  4. 5
      sigi/urls.py

18
sigi/apps/convenios/admin.py

@ -2,6 +2,7 @@
from django.contrib import admin from django.contrib import admin
from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo
from sigi.apps.servicos.models import Servico from sigi.apps.servicos.models import Servico
from django.http import HttpResponseRedirect
class AnexosInline(admin.TabularInline): class AnexosInline(admin.TabularInline):
model = Anexo model = Anexo
@ -33,17 +34,29 @@ class ConvenioAdmin(admin.ModelAdmin):
'data_devolucao_via', 'data_postagem_correio')} 'data_devolucao_via', 'data_postagem_correio')}
), ),
) )
actions = ['delete_selected', 'relatorio']
inlines = (AnexosInline, EquipamentoPrevistoInline) inlines = (AnexosInline, EquipamentoPrevistoInline)
list_display = ('id', 'casa_legislativa', list_display = ('id', 'casa_legislativa',
'num_processo_sf', 'data_adesao') 'num_processo_sf', 'data_adesao', 'projeto')
list_filter = ('data_adesao', 'data_retorno_assinatura', list_filter = ('data_adesao', 'data_retorno_assinatura',
'data_termo_aceite', 'data_devolucao_via', 'data_termo_aceite', 'data_devolucao_via',
'data_postagem_correio') 'data_postagem_correio', 'projeto')
ordering = ('-id',) ordering = ('-id',)
raw_id_fields = ('casa_legislativa',) raw_id_fields = ('casa_legislativa',)
search_fields = ('id', 'casa_legislativa__nome', search_fields = ('id', 'casa_legislativa__nome',
'num_processo_sf', 'casa_legislativa__municipio__nome', 'num_processo_sf', 'casa_legislativa__municipio__nome',
'casa_legislativa__municipio__uf__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): class EquipamentoPrevistoAdmin(admin.ModelAdmin):
list_display = ('convenio', 'equipamento', 'quantidade') list_display = ('convenio', 'equipamento', 'quantidade')
@ -56,4 +69,3 @@ class EquipamentoPrevistoAdmin(admin.ModelAdmin):
admin.site.register(Projeto) admin.site.register(Projeto)
admin.site.register(Convenio, ConvenioAdmin) admin.site.register(Convenio, ConvenioAdmin)
admin.site.register(EquipamentoPrevisto, EquipamentoPrevistoAdmin) admin.site.register(EquipamentoPrevisto, EquipamentoPrevistoAdmin)
admin.site.register(Anexo, AnexoAdmin)

31
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): class CasasAderidasReport(object):
pass pass
@ -9,3 +12,31 @@ class CasasComEquipamentosReport(object):
class SemEquipamentosReport(object): class SemEquipamentosReport(object):
pass 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}

25
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

5
sigi/urls.py

@ -8,11 +8,14 @@ import sigi.admin.filterspecs
urlpatterns = patterns( urlpatterns = patterns(
'', '',
# reports # reports labels
(r'^casas/casalegislativa/labels/', (r'^casas/casalegislativa/labels/',
'sigi.apps.casas.views.labels_report'), 'sigi.apps.casas.views.labels_report'),
(r'^casas/casalegislativa/(?P<id>\w+)/labels/', (r'^casas/casalegislativa/(?P<id>\w+)/labels/',
'sigi.apps.casas.views.labels_report'), 'sigi.apps.casas.views.labels_report'),
# reports
(r'^convenios/convenio/reports/',
'sigi.apps.convenios.views.report'),
# automatic interface based on admin # automatic interface based on admin
(r'^(.*)', sites.default.root), (r'^(.*)', sites.default.root),

Loading…
Cancel
Save