Browse Source

Merge pull request #558 from interlegis/adiciona-novos-campos-a-pesquisa-norma-juridica

Adiciona novos campos a pesquisa de norma juridica
pull/579/head
Edward 8 years ago
committed by GitHub
parent
commit
3f8ed14a21
  1. 29
      sapl/norma/forms.py
  2. 17
      sapl/norma/views.py

29
sapl/norma/forms.py

@ -5,6 +5,7 @@ from crispy_forms.layout import Fieldset, Layout
from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa
@ -20,6 +21,16 @@ def get_esferas():
('M', 'Municipal')]
YES_NO_CHOICES = [('', '---------'),
(True, _('Sim')),
(False, _('Não'))]
ORDENACAO_CHOICES = [('', '---------'),
('tipo,ano,numero', _('Tipo/Ano/Número')),
('data,tipo,ano,numero', _('Data/Tipo/Ano/Número'))]
# TODO termos, pesquisa textual, assunto(M2M)
class NormaJuridicaPesquisaForm(ModelForm):
periodo_inicial = forms.DateField(label=u'Período Inicial',
@ -58,6 +69,18 @@ class NormaJuridicaPesquisaForm(ModelForm):
empty_label='Selecione'
)
em_vigencia = forms.ChoiceField(
label='Em vigência?',
choices=YES_NO_CHOICES,
required=False)
ordenacao = forms.ChoiceField(
label='Ordenação',
choices=ORDENACAO_CHOICES,
required=False)
numero = forms.IntegerField(required=False)
class Meta:
model = NormaJuridica
fields = ['tipo',
@ -82,10 +105,14 @@ class NormaJuridicaPesquisaForm(ModelForm):
row4 = to_row(
[('publicacao_inicial', 6), ('publicacao_final', 6)])
row5 = to_row(
[('em_vigencia', 6),
('ordenacao', 6)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset('Pesquisa Norma Juridica',
row1, row2, row3, row4),
row1, row2, row3, row4, row5),
form_actions(save_label='Pesquisar')
)
super(NormaJuridicaPesquisaForm, self).__init__(*args, **kwargs)

17
sapl/norma/views.py

@ -89,6 +89,10 @@ class NormaPesquisaView(FormView):
if form.data['publicacao_inicial'] and form.data['publicacao_final']:
kwargs['publicacao_inicial'] = form.data['publicacao_inicial']
kwargs['publicacao_final'] = form.data['publicacao_final']
if form.data['ordenacao']:
kwargs['ordenacao'] = form.data['ordenacao']
if form.data['em_vigencia']:
kwargs['em_vigencia'] = form.data['em_vigencia']
request.session['kwargs'] = kwargs
return redirect('sapl.norma:list_pesquisa_norma')
@ -101,7 +105,18 @@ class PesquisaNormaListView(ListView):
def get_queryset(self):
kwargs = self.request.session['kwargs']
normas = NormaJuridica.objects.all().order_by('-ano', '-numero')
if 'ordenacao' in kwargs:
ordenacao = kwargs.pop('ordenacao').split(',')
for o in ordenacao:
normas = NormaJuridica.objects.all().order_by(o)
else:
normas = NormaJuridica.objects.all()
if 'em_vigencia' in kwargs:
del kwargs['em_vigencia']
normas = normas.filter(
data_vigencia__lte=datetime.now().date())
if 'periodo_inicial' and 'publicacao_inicial' in kwargs:
periodo_inicial = datetime.strptime(

Loading…
Cancel
Save