From 696a62df92c27357b39c5ef3ff667f5ff6e9f3ab Mon Sep 17 00:00:00 2001 From: "Camilo Carlos (Estagiario)" Date: Mon, 28 Feb 2011 21:19:05 +0000 Subject: [PATCH] =?UTF-8?q?Adi=C3=A7=C3=A3o=20da=20funcionalidade=20para?= =?UTF-8?q?=20selecionar=20v=C3=A1rias=20casas=20de=20diferentes=20estados?= =?UTF-8?q?=20e=20gerar=20etiquetas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/casas/admin.py | 18 +++++++++++++++++- sigi/apps/casas/views.py | 9 ++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index 97f7897..1279809 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -30,7 +30,7 @@ class CasaLegislativaAdmin(admin.ModelAdmin): form = CasaLegislativaForm change_form_template = 'casas/change_form.html' change_list_template = 'casas/change_list.html' - actions = ['etiqueta','relatorio','relatorio_csv','relatorio_completo','etiqueta_sem_presidente'] + actions = ['etiqueta','relatorio','relatorio_csv','relatorio_completo','etiqueta_sem_presidente', 'adicionar_casas', 'teste'] inlines = (TelefonesInline, ContatosInline, ConveniosInline) list_display = ('nome','municipio','presidente','logradouro') list_display_links = ('nome',) @@ -81,6 +81,22 @@ class CasaLegislativaAdmin(admin.ModelAdmin): return export_csv(request) relatorio_csv.short_description = u"Exportar casa(s) selecionada(s) para CSV" + def adicionar_casas(modelAdmin, request, queryset): + if request.method == 'POST': + ids_selecionados = request.POST.getlist('_selected_action') + print "Selecionados atual :", + print ids_selecionados + if request.session.has_key('ids_selecionados_etiqueta') == False: + request.session['ids_selecionados_etiqueta'] = ids_selecionados + else: + lista = request.session['ids_selecionados_etiqueta'] + print "Selecionados anteriormente :", + print lista + lista.extend(ids_selecionados) + print "Todos selecionados :", + print lista + request.session['ids_selecionados_etiqueta'] = lista + def get_actions(self, request): actions = super(CasaLegislativaAdmin, self).get_actions(request) del actions['delete_selected'] diff --git a/sigi/apps/casas/views.py b/sigi/apps/casas/views.py index 6f69817..92e1e24 100644 --- a/sigi/apps/casas/views.py +++ b/sigi/apps/casas/views.py @@ -36,7 +36,14 @@ def get_for_qs(get,qs): def labels_report(request, id=None,queryset=None): """ TODO: adicionar suporte para resultado de pesquisa do admin. """ - if queryset: + if request.session.has_key('ids_selecionados_etiqueta') == True: + ids = request.session['ids_selecionados_etiqueta'] + del request.session['ids_selecionados_etiqueta'] +# request.session.modified = True + print "Impressao", + print ids + qs = CasaLegislativa.objects.filter(pk__in=ids) + elif queryset: qs = queryset else: qs = CasaLegislativa.objects.all()