@ -11,6 +11,28 @@ 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.
"""
"""
@ -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,15 +70,16 @@ 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 :
qs = queryset
else :
qs = CasaLegislativa . objects . all ( )
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 ( ' ../ ' )
@ -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 ( ' ../ ' )
@ -117,14 +131,10 @@ 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 )