Browse Source

Comeca a refatoracao

pull/339/head
Eduardo Calil 9 years ago
parent
commit
5c161e8d01
  1. 234
      protocoloadm/forms.py
  2. 6
      protocoloadm/views.py

234
protocoloadm/forms.py

@ -5,11 +5,14 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import crispy_layout_mixin import crispy_layout_mixin
import sapl import sapl
import django_filters
from crispy_layout_mixin import form_actions from crispy_layout_mixin import form_actions
from materia.models import Autor, TipoMateriaLegislativa from materia.models import Autor, TipoMateriaLegislativa
from sapl.utils import RANGE_ANOS from sapl.utils import RANGE_ANOS
@ -25,108 +28,179 @@ NATUREZA_PROCESSO = [('0', 'Administrativo'),
('', 'Ambos')] ('', 'Ambos')]
def get_range_anos(): ANO_CHOICES = [('', '---------')] + RANGE_ANOS
return [('', 'Selecione')] \
+ [(year, year) for year in range(date.today().year, 1960, -1)]
class ProtocoloForm(forms.Form): # class ProtocoloForm(forms.Form):
YEARS = get_range_anos() # YEARS = get_range_anos()
tipo_protocolo = forms.ChoiceField(required=False, # tipo_protocolo = forms.ChoiceField(required=False,
label='Tipo de Protocolo', # label='Tipo de Protocolo',
choices=TIPOS_PROTOCOLO, # choices=TIPOS_PROTOCOLO,
widget=forms.Select( # widget=forms.Select(
attrs={'class': 'selector'})) # attrs={'class': 'selector'}))
numero_protocolo = forms.CharField( # numero_protocolo = forms.CharField(
label='Número de Protocolo', required=False) # label='Número de Protocolo', required=False)
ano = forms.ChoiceField(required=False, # ano = forms.ChoiceField(required=False,
label='Ano', # label='Ano',
choices=YEARS, # choices=YEARS,
widget=forms.Select( # widget=forms.Select(
attrs={'class': 'selector'})) # attrs={'class': 'selector'}))
inicial = forms.DateField(label='Data Inicial', # inicial = forms.DateField(label='Data Inicial',
required=False, # required=False,
widget=forms.TextInput( # widget=forms.TextInput(
attrs={'class': 'dateinput'})) # attrs={'class': 'dateinput'}))
final = forms.DateField(label='Data Final', required=False, # final = forms.DateField(label='Data Final', required=False,
widget=forms.TextInput( # widget=forms.TextInput(
attrs={'class': 'dateinput'})) # attrs={'class': 'dateinput'}))
natureza_processo = forms.ChoiceField(required=False, # natureza_processo = forms.ChoiceField(required=False,
label='Natureza Processo', # label='Natureza Processo',
choices=[ # choices=[
('0', 'Administrativo'), # ('0', 'Administrativo'),
('1', 'Legislativo'), # ('1', 'Legislativo'),
('', 'Ambos')]) # ('', 'Ambos')])
tipo_documento = forms.ModelChoiceField( # tipo_documento = forms.ModelChoiceField(
label='Tipo de Documento', # label='Tipo de Documento',
required=False, # required=False,
queryset=TipoDocumentoAdministrativo.objects.all(), # queryset=TipoDocumentoAdministrativo.objects.all(),
empty_label='Selecione', # empty_label='Selecione',
) # )
interessado = forms.CharField(label='Interessado', required=False) # interessado = forms.CharField(label='Interessado', required=False)
tipo_materia = forms.ModelChoiceField( # tipo_materia = forms.ModelChoiceField(
label='Tipo de Matéria', # label='Tipo de Matéria',
required=False, # required=False,
queryset=TipoMateriaLegislativa.objects.all(), # queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione', # empty_label='Selecione',
) # )
autor = forms.CharField(widget=forms.HiddenInput(), required=False) # autor = forms.CharField(widget=forms.HiddenInput(), required=False)
assunto = forms.CharField(label='Assunto', required=False) # assunto = forms.CharField(label='Assunto', required=False)
def __init__(self, *args, **kwargs): # def __init__(self, *args, **kwargs):
row1 = crispy_layout_mixin.to_row( # super(ProtocoloForm, self).__init__(
[('numero_protocolo', 6), # *args, **kwargs)
('ano', 6)])
row2 = crispy_layout_mixin.to_row(
[('inicial', 6),
('final', 6)])
row3 = crispy_layout_mixin.to_row( # Importar essa classe de materias.views quando for feito o Merge do branch 217
[('tipo_documento', 4), class RangeWidgetOverride(forms.MultiWidget):
('tipo_protocolo', 4),
('tipo_materia', 4)])
row4 = crispy_layout_mixin.to_row( def __init__(self, attrs=None):
[('interessado', 6), widgets = (forms.DateInput(format='%d/%m/%Y',
('assunto', 6)]) attrs={'class': 'dateinput',
'placeholder': 'Inicial'}),
forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput',
'placeholder': 'Final'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs)
row5 = crispy_layout_mixin.to_row( def decompress(self, value):
[('autor', 0), if value:
(Button('pesquisar', return [value.start, value.stop]
'Pesquisar Autor', return [None, None]
css_class='btn btn-primary btn-sm'), 2),
(Button('limpar',
'Limpar Autor',
css_class='btn btn-primary btn-sm'), 10)])
row6 = crispy_layout_mixin.to_row( def format_output(self, rendered_widgets):
[('natureza_processo', 12)]) return ''.join(rendered_widgets)
self.helper = FormHelper()
self.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'), class ProtocoloFilterSet(django_filters.FilterSet):
row1, row2,
row3, row4, filter_overrides = {models.DateField: {
HTML(sapl.utils.autor_label), 'filter_class': django_filters.DateFromToRangeFilter,
HTML(sapl.utils.autor_modal), 'extra': lambda f: {
row5, 'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')),
row6, 'widget': RangeWidgetOverride}
form_actions(save_label='Pesquisar'))) }}
super(ProtocoloForm, self).__init__(
*args, **kwargs) ano = django_filters.ChoiceFilter(required=False,
label=u'Ano da Matéria',
choices=ANO_CHOICES,
help_text="")
assunto_ementa = django_filters.CharFilter(lookup_expr='icontains')
interessado = django_filters.CharFilter(lookup_expr='icontains')
class Meta:
model = Protocolo
fields = ['tipo_protocolo',
'numero',
'tipo_documento',
'data_publicacao',
'tipo_materia',
'autor'
]
order_by = (
('', 'Selecione'),
('CRE', 'Ordem Crescente'),
('DEC', 'Ordem Decrescente'),
)
order_by_mapping = {
'': [],
'CRE': ['ano', 'numero'],
'DEC': ['-ano', '-numero'],
}
def get_order_by(self, order_value):
if order_value in self.order_by_mapping:
return self.order_by_mapping[order_value]
else:
return super(ProtocoloFilterSet,
self).get_order_by(order_value)
def __init__(self, *args, **kwargs):
super(ProtocoloFilterSet, self).__init__(*args, **kwargs)
self.filters['autor'].label = 'Tipo de Matéria'
self.filters['assunto_ementa'].label = 'Assunto'
row1 = crispy_layout_mixin.to_row(
[('numero', 6),
('ano', 6)])
row2 = crispy_layout_mixin.to_row(
[('inicial', 6),
('final', 6)])
row3 = crispy_layout_mixin.to_row(
[('tipo_documento', 4),
('tipo_protocolo', 4),
('tipo_materia', 4)])
row4 = crispy_layout_mixin.to_row(
[('interessado', 6),
('assunto_ementa', 6)])
row5 = crispy_layout_mixin.to_row(
[('autor', 0),
(Button('pesquisar',
'Pesquisar Autor',
css_class='btn btn-primary btn-sm'), 2),
(Button('limpar',
'Limpar Autor',
css_class='btn btn-primary btn-sm'), 10)])
self.helper = FormHelper()
self.form.helper.form_method = 'GET'
self.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'),
row1, row2,
row3, row4,
HTML(sapl.utils.autor_label),
HTML(sapl.utils.autor_modal),
row5,
form_actions(save_label='Pesquisar')))
class AnularProcoloAdmForm(ModelForm): class AnularProcoloAdmForm(ModelForm):

6
protocoloadm/views.py

@ -63,12 +63,6 @@ class ProtocoloPesquisaView(FormView):
request.POST['inicial'], request.POST['inicial'],
'%d/%m/%Y').strftime('%Y-%m-%d') '%d/%m/%Y').strftime('%Y-%m-%d')
# if request.POST['final']:
# kwargs['final'] = request.POST['final']
if request.POST['natureza_processo']:
kwargs['tipo_protocolo'] = request.POST['natureza_processo']
if request.POST['tipo_documento']: if request.POST['tipo_documento']:
kwargs['tipo_documento'] = request.POST['tipo_documento'] kwargs['tipo_documento'] = request.POST['tipo_documento']

Loading…
Cancel
Save