From b1c4ebe81c118237cba5012c298939b35768a58a Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 27 Oct 2016 14:45:17 -0200 Subject: [PATCH] Adiciona 'assunto' na pesquisa de norma --- sapl/norma/forms.py | 28 +++++++++++++++------------- sapl/norma/views.py | 5 +++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index cc9b0569c..a767c37fa 100644 --- a/sapl/norma/forms.py +++ b/sapl/norma/forms.py @@ -12,7 +12,7 @@ from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.utils import RANGE_ANOS -from .models import AssuntoNormaRelationship, NormaJuridica +from .models import AssuntoNorma, AssuntoNormaRelationship, NormaJuridica def get_esferas(): @@ -101,6 +101,13 @@ class NormaJuridicaPesquisaForm(ModelForm): numero = forms.IntegerField(required=False) + assunto = forms.ModelChoiceField( + label='Assunto', + required=False, + queryset=AssuntoNorma.objects.all(), + empty_label='Selecione' + ) + class Meta: model = NormaJuridica fields = ['tipo', @@ -109,25 +116,20 @@ class NormaJuridicaPesquisaForm(ModelForm): 'periodo_inicial', 'periodo_final', 'publicacao_inicial', - 'publicacao_final'] + 'publicacao_final', + 'assunto'] def __init__(self, *args, **kwargs): - row1 = to_row( - [('tipo', 12)]) + row1 = to_row([('tipo', 12)]) - row2 = to_row( - [('numero', 6), ('ano', 6)]) + row2 = to_row([('numero', 6), ('ano', 6)]) - row3 = to_row( - [('periodo_inicial', 6), ('periodo_final', 6)]) + row3 = to_row([('periodo_inicial', 6), ('periodo_final', 6)]) - row4 = to_row( - [('publicacao_inicial', 6), ('publicacao_final', 6)]) + row4 = to_row([('publicacao_inicial', 6), ('publicacao_final', 6)]) - row5 = to_row( - [('em_vigencia', 6), - ('ordenacao', 6)]) + row5 = to_row([('em_vigencia', 4), ('ordenacao', 4), ('assunto', 4)]) self.helper = FormHelper() self.helper.layout = Layout( diff --git a/sapl/norma/views.py b/sapl/norma/views.py index 7e6e195d0..283c43bb8 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -135,6 +135,8 @@ class NormaPesquisaView(FormView): kwargs['ordenacao'] = form.data['ordenacao'] if form.data['em_vigencia']: kwargs['em_vigencia'] = form.data['em_vigencia'] + if form.data['assunto']: + kwargs['assunto'] = form.data['assunto'] request.session['kwargs'] = kwargs return redirect('sapl.norma:list_pesquisa_norma') @@ -202,6 +204,9 @@ class PesquisaNormaListView(ListView): if 'ano' in kwargs: normas = normas.filter(ano=kwargs['ano']) + if 'assunto' in kwargs: + normas = normas.filter(assuntos=kwargs['assunto']) + return normas def get_context_data(self, **kwargs):