From c0fb1f79f8782ea1c938bb727c3d8fd580434811 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 14 Mar 2016 11:27:14 -0300 Subject: [PATCH] Adiciona modal para selecao de autor --- materia/forms.py | 5 +++-- materia/urls.py | 18 +++++++++--------- materia/views.py | 1 + protocoloadm/urls.py | 4 +++- protocoloadm/views.py | 37 +++++++++++++++++++++++++++++++++++-- sapl/utils.py | 20 ++++++++++++++++++++ 6 files changed, 71 insertions(+), 14 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index a8e7cbe2d..c62b736f3 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -1,10 +1,11 @@ from crispy_forms.helper import FormHelper -from crispy_forms.layout import Column, Fieldset, Layout, Submit, Button, HTML +from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Submit from django import forms from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ -import sapl + import crispy_layout_mixin +import sapl from crispy_layout_mixin import form_actions from norma.models import LegislacaoCitada, TipoNormaJuridica from parlamentares.models import Parlamentar, Partido diff --git a/materia/urls.py b/materia/urls.py index fd195051c..b37da3a43 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -11,15 +11,15 @@ from materia.views import (AcompanhamentoConfirmarView, MateriaAnexadaEditView, MateriaAnexadaView, MateriaLegislativaPesquisaView, MateriaTaView, NumeracaoEditView, NumeracaoView, - PesquisaMateriaListView, ProposicaoListView, - ProposicaoTaView, ProposicaoView, RelatoriaEditView, - RelatoriaView, TramitacaoEditView, TramitacaoView, - autor_crud, materia_legislativa_crud, orgao_crud, - origem_crud, regime_tramitacao_crud, - status_tramitacao_crud, tipo_autor_crud, - tipo_documento_crud, tipo_fim_relatoria_crud, - tipo_materia_crud, tipo_proposicao_crud, - unidade_tramitacao_crud, ProposicaoEditView) + PesquisaMateriaListView, ProposicaoEditView, + ProposicaoListView, ProposicaoTaView, + ProposicaoView, RelatoriaEditView, RelatoriaView, + TramitacaoEditView, TramitacaoView, autor_crud, + materia_legislativa_crud, orgao_crud, origem_crud, + regime_tramitacao_crud, status_tramitacao_crud, + tipo_autor_crud, tipo_documento_crud, + tipo_fim_relatoria_crud, tipo_materia_crud, + tipo_proposicao_crud, unidade_tramitacao_crud) materia_legislativa_patterns = materia_legislativa_crud.urlpatterns diff --git a/materia/views.py b/materia/views.py index 0200e0d34..40889c04e 100644 --- a/materia/views.py +++ b/materia/views.py @@ -1404,6 +1404,7 @@ class ProposicaoEditView(CreateView): else: return self.render_to_response({'form': form}) + class MateriaTaView(IntegracaoTaView): model = MateriaLegislativa model_type_foreignkey = TipoMateriaLegislativa diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index eb427c88d..bf8244ff9 100644 --- a/protocoloadm/urls.py +++ b/protocoloadm/urls.py @@ -18,7 +18,7 @@ from protocoloadm.views import (AnularProtocoloAdmView, TramitacaoAdmIncluirView, TramitacaoAdmView, documento_acessorio_administrativo_crud, documento_administrativo_crud, - protocolo_documento_crud, + pesquisa_autores, protocolo_documento_crud, protocolo_materia_crud, status_tramitacao_administrativo_crud, tipo_documento_administrativo_crud, @@ -91,4 +91,6 @@ urlpatterns = [ name='proposicoes_incorporadas'), url(r'^proposicoes/(?P\d+)/proposicao', ProposicaoDetailView.as_view(), name='proposicao_view'), + url(r'^proposicoes/pesquisar_autores', + pesquisa_autores, name='pesquisar_autores') ] diff --git a/protocoloadm/views.py b/protocoloadm/views.py index e08698cb1..6e9b796ec 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -1,10 +1,11 @@ +import json from datetime import date, datetime from re import sub from braces.views import FormValidMessageMixin from django.core.urlresolvers import reverse, reverse_lazy -from django.db.models import Max -from django.http import HttpResponseRedirect +from django.db.models import Q, Max +from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import redirect from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ @@ -656,3 +657,35 @@ class TramitacaoAdmDeleteView(DetailView): return self.render_to_response({'documento': documento, 'tramitacoes': tramitacoes}) + + +def pesquisa_autores(request): + q = '' + if request.method == 'GET': + q = request.GET.get('q', '') + + autor = Autor.objects.filter( + Q(nome__icontains=q) | + Q(parlamentar__nome_parlamentar__icontains=q) | + Q(comissao__nome__icontains=q) + ) + + autores = [] + + for a in autor: + nome = '' + if a.nome: + nome = a.nome + elif a.parlamentar: + nome = a.parlamentar.nome_parlamentar + elif a.comissao: + nome = a.comissao.nome + + autores.append((a.id, nome)) + + autores = sorted(autores, key=lambda x: x[1]) + + return HttpResponse(json.dumps(autores, + sort_keys=True, + ensure_ascii=False), + content_type="application/json; charset=utf-8") diff --git a/sapl/utils.py b/sapl/utils.py index 615a6b1e9..875bfa563 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -5,6 +5,26 @@ from django.apps import apps from django.contrib import admin from django.utils.translation import ugettext_lazy as _ +autor_label = ''' +
+ Autor: +
+''' + + +autor_modal = ''' + +''' + def register_all_models_in_admin(module_name): appname = module_name.split('.')[0]