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. 22
      sigi/apps/casas/admin.py
  2. 72
      sigi/apps/casas/views.py
  3. 2
      sigi/apps/convenios/admin.py
  4. 57
      sigi/apps/convenios/views.py
  5. 5
      sigi/urls.py

22
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 django.http import HttpResponse, HttpResponseRedirect
from sigi.apps.casas.reports import CasasLegislativasLabels, CasasLegislativasReport from sigi.apps.casas.reports import CasasLegislativasLabels, CasasLegislativasReport
from geraldo.generators import PDFGenerator 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 from sigi.apps.utils import queryset_ascii
class ContatosInline(generic.GenericTabularInline): class ContatosInline(generic.GenericTabularInline):
@ -60,30 +61,23 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
extra_context={'query_str': '?' + request.META['QUERY_STRING']} extra_context={'query_str': '?' + request.META['QUERY_STRING']}
) )
def etiqueta(modelAdmin,request,queryset): def etiqueta(modelAdmin,request,queryset):
response = HttpResponse(mimetype='application/pdf')
return labels_report(request,queryset=queryset) return labels_report(request,queryset=queryset)
etiqueta.short_description = "Gerar etiqueta(s) da(s) casa(s) selecionada(s)" etiqueta.short_description = "Gerar etiqueta(s) da(s) casa(s) selecionada(s)"
def etiqueta_sem_presidente(modelAdmin,request,queryset): def etiqueta_sem_presidente(modelAdmin,request,queryset):
response = HttpResponse(mimetype='application/pdf')
return labels_report_sem_presidente(request,queryset=queryset) return labels_report_sem_presidente(request,queryset=queryset)
etiqueta_sem_presidente.short_description = "Gerar etiqueta(s) sem presidente da(s) casa(s) selecionada(s)" etiqueta_sem_presidente.short_description = "Gerar etiqueta(s) sem presidente da(s) casa(s) selecionada(s)"
def relatorio(modelAdmin,request,queryset): def relatorio(modelAdmin,request,queryset):
response = HttpResponse(mimetype='application/pdf') return report(request,queryset=queryset)
report = CasasLegislativasReport(queryset=queryset)
report.generate_by(PDFGenerator, filename=response)
return response
relatorio.short_description = u"Exportar a(s) casa(s) selecionada(s) para PDF" relatorio.short_description = u"Exportar a(s) casa(s) selecionada(s) para PDF"
def relatorio_completo(modelAdmin,request,queryset): def relatorio_completo(modelAdmin,request,queryset):
response = HttpResponse(mimetype='application/pdf')
return casa_info(request,queryset=queryset) return casa_info(request,queryset=queryset)
relatorio_completo.short_description = u"Gerar relatório completo da(s) casa(s) selecionada(s)" relatorio_completo.short_description = u"Gerar relatório completo da(s) casa(s) selecionada(s)"
def relatorio_csv(modelAdmin,request,queryset): def relatorio_csv(modelAdmin,request,queryset):
response = HttpResponse(mimetype='text/csv')
return export_csv(request) return export_csv(request)
relatorio_csv.short_description = u"Exportar casa(s) selecionada(s) para CSV" relatorio_csv.short_description = u"Exportar casa(s) selecionada(s) para CSV"

72
sigi/apps/casas/views.py

@ -11,9 +11,31 @@ from sigi.apps.casas.reports import InfoCasaLegislativa
import csv 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): def labels_report(request, id=None,queryset=None):
""" TODO: adicionar suporte para resultado de pesquisa do admin. """ TODO: adicionar suporte para resultado de pesquisa do admin.
""" """
if queryset: if queryset:
qs = queryset qs = queryset
else: else:
@ -21,10 +43,7 @@ def labels_report(request, id=None,queryset=None):
if id: if id:
qs = qs.filter(pk=id) qs = qs.filter(pk=id)
elif request.GET: elif request.GET:
kwargs = {} qs = get_for_qs(request.GET,qs)
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
report = CasasLegislativasLabels(queryset=qs) report = CasasLegislativasLabels(queryset=qs)
@ -42,10 +61,7 @@ def labels_report_sem_presidente(request, id=None,queryset=None):
if id: if id:
qs = qs.filter(pk=id) qs = qs.filter(pk=id)
elif request.GET: elif request.GET:
kwargs = {} qs = get_for_qs(request.GET,qs)
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
report = CasasLegislativasLabelsSemPresidente(queryset=qs) report = CasasLegislativasLabelsSemPresidente(queryset=qs)
@ -54,17 +70,18 @@ def labels_report_sem_presidente(request, id=None,queryset=None):
return response return response
def report(request, id=None): def report(request, id=None,queryset=None):
qs = CasaLegislativa.objects.all().order_by('municipio__uf','nome') if queryset:
if id: qs = queryset
qs = qs.filter(pk=id) else:
elif request.GET: qs = CasaLegislativa.objects.all()
kwargs = {} if id:
for k, v in request.GET.iteritems(): qs = qs.filter(pk=id)
kwargs[str(k)] = v elif request.GET:
qs = qs.filter(**kwargs) qs = get_for_qs(request.GET,qs)
if not qs:
return HttpResponseRedirect('../') if not qs:
return HttpResponseRedirect('../')
#qs.order_by('municipio__uf','nome') #qs.order_by('municipio__uf','nome')
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
@ -80,10 +97,7 @@ def casa_info(request,id=None,queryset=None):
if id: if id:
qs = qs.filter(pk=id) qs = qs.filter(pk=id)
elif request.GET: elif request.GET:
kwargs = {} qs = get_for_qs(request.GET,qs)
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
if not qs: if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
@ -116,15 +130,11 @@ def casa_info(request,id=None,queryset=None):
def casas_sem_convenio_report(request): def casas_sem_convenio_report(request):
qs = CasaLegislativa.objects.filter(convenio=None).order_by('municipio__uf','nome') qs = CasaLegislativa.objects.filter(convenio=None).order_by('municipio__uf','nome')
if request.GET: if request.GET:
kwargs = {} qs = get_for_qs(request.GET,qs)
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
if not qs: if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
#qs.order_by('municipio__uf','nome')
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
report = CasasSemConvenioReport(queryset=qs) report = CasasSemConvenioReport(queryset=qs)
report.generate_by(PDFGenerator, filename=response) 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_display_links = ('num_convenio','casa_legislativa',)
list_filter = ('projeto','casa_legislativa','conveniada', 'equipada') list_filter = ('projeto','casa_legislativa','conveniada', 'equipada')
#date_hierarchy = 'data_adesao' #date_hierarchy = 'data_adesao'
ordering = ('casa_legislativa__municipio__uf','-id',) ordering = ('casa_legislativa__municipio__uf','casa_legislativa','-id',)
raw_id_fields = ('casa_legislativa',) raw_id_fields = ('casa_legislativa',)
queryset = queryset_ascii queryset = queryset_ascii
search_fields = ('id', 'search_text',#'casa_legislativa__nome', search_fields = ('id', 'search_text',#'casa_legislativa__nome',

57
sigi/apps/convenios/views.py

@ -14,25 +14,44 @@ from django.template import Context, loader
import datetime 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 get_for_qs(get,qs):
kwargs = {}
ids = 0
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): def report_por_cm(request, id=None):
qs = Convenio.objects.filter(casa_legislativa__tipo__sigla='CM').order_by('casa_legislativa__municipio__uf','casa_legislativa') qs = Convenio.objects.filter(casa_legislativa__tipo__sigla='CM').order_by('casa_legislativa__municipio__uf','casa_legislativa')
if id: if id:
qs = qs.filter(pk=id) qs = qs.filter(pk=id)
elif request.GET: #Se tiver algum parametro de pesquisa elif request.GET: #Se tiver algum parametro de pesquisa
kwargs = {} qs = get_for_qs(request.GET,qs)
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])
if not qs: if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')
@ -45,17 +64,7 @@ def report_por_al(request, id=None):
if id: if id:
qs = qs.filter(pk=id) qs = qs.filter(pk=id)
elif request.GET: #Se tiver algum parametro de pesquisa elif request.GET: #Se tiver algum parametro de pesquisa
kwargs = {} qs = get_for_qs(request.GET,qs)
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])
if not qs: if not qs:
return HttpResponseRedirect('../') return HttpResponseRedirect('../')
response = HttpResponse(mimetype='application/pdf') response = HttpResponse(mimetype='application/pdf')

5
sigi/urls.py

@ -16,6 +16,11 @@ urlpatterns = patterns(
'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 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 # reports
(r'^casas/casalegislativa/reports/', (r'^casas/casalegislativa/reports/',
'sigi.apps.casas.views.report'), 'sigi.apps.casas.views.report'),

Loading…
Cancel
Save