@ -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 )