From 2043c7c4f59c69b626c6f363c9a56088d9f67fe9 Mon Sep 17 00:00:00 2001 From: Breno Teixeira Date: Wed, 19 Jun 2013 11:34:10 -0300 Subject: [PATCH] =?UTF-8?q?emiss=C3=A3o=20de=20etiquetas=20para=20parlamen?= =?UTF-8?q?tares=20a=20partir=20de=20casas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/casas/views.py | 47 ++++++++++++++++++++++++++++++++ sigi/apps/parlamentares/views.py | 12 ++++---- sigi/urls.py | 4 +-- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index 95f8265..be79661 100644 --- a/sigi/apps/casas/views.py +++ b/sigi/apps/casas/views.py @@ -154,6 +154,53 @@ def labels_report(request, id=None, tipo=None, formato='3x9_etiqueta'): return response +def labels_report_parlamentar(request, id=None, formato='3x9_etiqueta'): + """ TODO: adicionar suporte para resultado de pesquisa do admin. + """ + + if request.POST: + if request.POST.has_key('tamanho_etiqueta'): + formato = request.POST['tamanho_etiqueta'] + + + if id: + legislaturas = [c.legislatura_set.latest('data_inicio') for c in CasaLegislativa.objects.filter(pk__in=id, legislatura__id__isnull=False).distinct()] + mandatos = reduce(lambda x, y: x | y, [l.mandato_set.all() for l in legislaturas]) + parlamentares = [m.parlamentar for m in mandatos] + qs = parlamentares + + else: + qs = carrinhoOrGet_for_parlamentar_qs(request) + + if not qs: + return HttpResponseRedirect('../') + + response = HttpResponse(mimetype='application/pdf') + response['Content-Disposition'] = 'attachment; filename=casas.pdf' + report = ParlamentaresLabels(queryset=qs, formato=formato) + report.generate_by(PDFGenerator, filename=response) + + return response + +def carrinhoOrGet_for_parlamentar_qs(request): + """ + Verifica se existe parlamentares na sessão se não verifica get e retorna qs correspondente. + """ + if request.session.has_key('carrinho_casas'): + ids = request.session['carrinho_casas'] + legislaturas = [c.legislatura_set.latest('data_inicio') for c in CasaLegislativa.objects.filter(pk__in=ids, legislatura__id__isnull=False).distinct()] + mandatos = reduce(lambda x, y: x | y, [l.mandato_set.all() for l in legislaturas]) + parlamentares = [m.parlamentar for m in mandatos] + qs = parlamentares + else: + legislaturas = [c.legislatura_set.latest('data_inicio') for c in CasaLegislativa.objects.all().distinct()] + mandatos = reduce(lambda x, y: x | y, [l.mandato_set.all() for l in legislaturas]) + parlamentares = [m.parlamentar for m in mandatos] + qs = parlamentares + if request.GET: + qs = get_for_qs(request.GET,qs) + return qs + def labels_report_sem_presidente(request, id=None, formato='2x5_etiqueta'): """ TODO: adicionar suporte para resultado de pesquisa do admin. """ diff --git a/sigi/apps/parlamentares/views.py b/sigi/apps/parlamentares/views.py index 8ae81b0..67042a7 100644 --- a/sigi/apps/parlamentares/views.py +++ b/sigi/apps/parlamentares/views.py @@ -11,6 +11,7 @@ from django.http import HttpResponse, HttpResponseRedirect from django.views.decorators.csrf import csrf_protect from django.template import RequestContext +from sigi.apps.casas.models import CasaLegislativa from sigi.apps.parlamentares.models import Parlamentar from sigi.apps.parlamentares.reports import ParlamentaresLabels @@ -67,10 +68,10 @@ def carrinhoOrGet_for_qs(request): Verifica se existe parlamentares na sessão se não verifica get e retorna qs correspondente. """ if request.session.has_key('carrinho_parlamentar'): - ids = request.session['carrinho_parlamentar'] - qs = Parlamentar.objects.filter(pk__in=ids) + ids = request.session['carrinho_parlamentar'] + qs = Parlamentar.objects.filter(pk__in=ids) else: - qs = Parlamentar.objects.all() + qs = Parlamentar.objects.all() if request.GET: qs = get_for_qs(request.GET,qs) return qs @@ -129,12 +130,11 @@ def labels_report(request, id=None, formato='3x9_etiqueta'): if request.POST: if request.POST.has_key('tipo_etiqueta'): tipo = request.POST['tipo_etiqueta'] - if request.POST.has_key('tamanho_etiqueta'): - formato = request.POST['tamanho_etiqueta'] if id: - qs = Parlamentar.objects.filter(pk=id) + qs = Parlamentar.objects.filter(pk=id) + else: qs = carrinhoOrGet_for_qs(request) diff --git a/sigi/urls.py b/sigi/urls.py index 6b8ac5d..c33d43c 100644 --- a/sigi/urls.py +++ b/sigi/urls.py @@ -32,9 +32,9 @@ urlpatterns = patterns( (r'^sigi/casas/casalegislativa/labels/', 'sigi.apps.casas.views.labels_report'), (r'^sigi/casas/casalegislativa/labels_parlamentar/', # parlamentar - 'sigi.apps.parlamentares.views.labels_report'), + 'sigi.apps.casas.views.labels_report_parlamentar'), (r'^sigi/casas/casalegislativa/(?P\w+)/labels_parlamentar/', # parlamentar - 'sigi.apps.parlamentares.views.labels_report'), + 'sigi.apps.casas.views.labels_report_parlamentar'), (r'^sigi/casas/casalegislativa/(?P\w+)/labels/', 'sigi.apps.casas.views.labels_report'), # reports labels parlamentares