Browse Source

Alterando geração de relatorios para que tratem ordenação do admin. Tirando codigos desnecessarios das actions do admin de casa. Acrescentando urls que faltaram para tratar etiqueta sem presidente

diagnosticos
Starlone (Estagiario) 14 years ago
parent
commit
47ce4fa5ec
  1. 12
      sigi/apps/casas/admin.py
  2. 56
      sigi/apps/casas/views.py
  3. 2
      sigi/apps/convenios/admin.py
  4. 45
      sigi/apps/convenios/views.py
  5. 5
      sigi/urls.py

12
sigi/apps/casas/admin.py

@ -8,7 +8,8 @@ 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, export_csv, labels_report_sem_presidente
from sigi.apps.casas.views import casa_info, labels_report, export_csv, \
labels_report_sem_presidente, report
from sigi.apps.utils import queryset_ascii
class ContatosInline(generic.GenericTabularInline):
@ -61,29 +62,22 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
)
def etiqueta(modelAdmin,request,queryset):
response = HttpResponse(mimetype='application/pdf')
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
return report(request,queryset=queryset)
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"

56
sigi/apps/casas/views.py

@ -11,6 +11,28 @@ from sigi.apps.casas.reports import InfoCasaLegislativa
import csv
def query_ordena(qs,o,ot):
list_display = ('nome','municipio','presidente','logradouro')
aux = list_display[(int(o)-1)]
if ot =='asc':
qs = qs.order_by(aux)
else:
qs = qs.order_by("-"+aux)
return qs
def get_for_qs(get,qs):
kwargs = {}
for k,v in get.iteritems():
if not k == 'o':
if k == "ot":
qs = query_ordena(qs,get["o"],get["ot"])
else:
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
return qs
def labels_report(request, id=None,queryset=None):
""" TODO: adicionar suporte para resultado de pesquisa do admin.
"""
@ -21,10 +43,7 @@ def labels_report(request, id=None,queryset=None):
if id:
qs = qs.filter(pk=id)
elif request.GET:
kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
qs = get_for_qs(request.GET,qs)
response = HttpResponse(mimetype='application/pdf')
report = CasasLegislativasLabels(queryset=qs)
@ -42,10 +61,7 @@ def labels_report_sem_presidente(request, id=None,queryset=None):
if id:
qs = qs.filter(pk=id)
elif request.GET:
kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
qs = get_for_qs(request.GET,qs)
response = HttpResponse(mimetype='application/pdf')
report = CasasLegislativasLabelsSemPresidente(queryset=qs)
@ -54,15 +70,16 @@ def labels_report_sem_presidente(request, id=None,queryset=None):
return response
def report(request, id=None):
qs = CasaLegislativa.objects.all().order_by('municipio__uf','nome')
def report(request, id=None,queryset=None):
if queryset:
qs = queryset
else:
qs = CasaLegislativa.objects.all()
if id:
qs = qs.filter(pk=id)
elif request.GET:
kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
qs = get_for_qs(request.GET,qs)
if not qs:
return HttpResponseRedirect('../')
@ -80,10 +97,7 @@ def casa_info(request,id=None,queryset=None):
if id:
qs = qs.filter(pk=id)
elif request.GET:
kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
qs = get_for_qs(request.GET,qs)
if not qs:
return HttpResponseRedirect('../')
@ -117,14 +131,10 @@ def casas_sem_convenio_report(request):
qs = CasaLegislativa.objects.filter(convenio=None).order_by('municipio__uf','nome')
if request.GET:
kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
qs = get_for_qs(request.GET,qs)
if not qs:
return HttpResponseRedirect('../')
#qs.order_by('municipio__uf','nome')
response = HttpResponse(mimetype='application/pdf')
report = CasasSemConvenioReport(queryset=qs)
report.generate_by(PDFGenerator, filename=response)

2
sigi/apps/convenios/admin.py

@ -47,7 +47,7 @@ class ConvenioAdmin(admin.ModelAdmin):
list_display_links = ('num_convenio','casa_legislativa',)
list_filter = ('projeto','casa_legislativa','conveniada', 'equipada')
#date_hierarchy = 'data_adesao'
ordering = ('casa_legislativa__municipio__uf','-id',)
ordering = ('casa_legislativa__municipio__uf','casa_legislativa','-id',)
raw_id_fields = ('casa_legislativa',)
queryset = queryset_ascii
search_fields = ('id', 'search_text',#'casa_legislativa__nome',

45
sigi/apps/convenios/views.py

@ -14,25 +14,44 @@ from django.template import Context, loader
import datetime
def query_ordena(qs,o,ot):
list_display = ('num_convenio', 'casa_legislativa',
'data_adesao','data_retorno_assinatura','data_termo_aceite',
'projeto',
)
aux = list_display[(int(o)-1)]
if ot =='asc':
qs = qs.order_by(aux)
else:
qs = qs.order_by("-"+aux)
return qs
def report_por_cm(request, id=None):
qs = Convenio.objects.filter(casa_legislativa__tipo__sigla='CM').order_by('casa_legislativa__municipio__uf','casa_legislativa')
if id:
qs = qs.filter(pk=id)
elif request.GET: #Se tiver algum parametro de pesquisa
def get_for_qs(get,qs):
kwargs = {}
ids = 0
for k, v in request.GET.iteritems():
for k,v in get.iteritems():
if not k == 'o':
if k == "ot":
qs = query_ordena(qs,get["o"],get["ot"])
else:
kwargs[str(k)] = v
if(str(k)=='ids'):
ids = 1
break
qs = qs.filter(**kwargs)
if ids:
query = 'id IN ('+ kwargs['ids'].__str__()+')'
qs = Convenio.objects.extra(where=[query])
return qs
def report_por_cm(request, id=None):
qs = Convenio.objects.filter(casa_legislativa__tipo__sigla='CM').order_by('casa_legislativa__municipio__uf','casa_legislativa')
if id:
qs = qs.filter(pk=id)
elif request.GET: #Se tiver algum parametro de pesquisa
qs = get_for_qs(request.GET,qs)
if not qs:
return HttpResponseRedirect('../')
response = HttpResponse(mimetype='application/pdf')
@ -45,17 +64,7 @@ def report_por_al(request, id=None):
if id:
qs = qs.filter(pk=id)
elif request.GET: #Se tiver algum parametro de pesquisa
kwargs = {}
ids = 0
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
if(str(k)=='ids'):
ids = 1
break
qs = qs.filter(**kwargs)
if ids:
query = 'id IN ('+ kwargs['ids'].__str__()+')'
qs = Convenio.objects.extra(where=[query])
qs = get_for_qs(request.GET,qs)
if not qs:
return HttpResponseRedirect('../')
response = HttpResponse(mimetype='application/pdf')

5
sigi/urls.py

@ -16,6 +16,11 @@ urlpatterns = patterns(
'sigi.apps.casas.views.labels_report'),
(r'^casas/casalegislativa/(?P<id>\w+)/labels/',
'sigi.apps.casas.views.labels_report'),
# reports labels sem presidente
(r'^casas/casalegislativa/labels_sem_presidente/',
'sigi.apps.casas.views.labels_report_sem_presidente'),
(r'^casas/casalegislativa/(?P<id>\w+)/labels_sem_presidente/',
'sigi.apps.casas.views.labels_report_sem_presidente'),
# reports
(r'^casas/casalegislativa/reports/',
'sigi.apps.casas.views.report'),

Loading…
Cancel
Save