From 6ad41b1ed802ec123b295ed5156473d021b48578 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 15 Mar 2016 09:02:01 -0300 Subject: [PATCH] Refatora protocolar documento e adiciona campo para buscar autor --- protocoloadm/forms.py | 119 +++++++++++---------- protocoloadm/views.py | 9 +- templates/protocoloadm/protocolo_list.html | 12 +-- 3 files changed, 74 insertions(+), 66 deletions(-) diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index 4f9f243e3..e801fe18a 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -1,5 +1,7 @@ +from datetime import date + from crispy_forms.helper import FormHelper -from crispy_forms.layout import HTML, Field, Fieldset, Layout, Submit +from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit from django import forms from django.core.exceptions import ObjectDoesNotExist from django.forms import ModelForm @@ -7,6 +9,7 @@ from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ import crispy_layout_mixin +import sapl from crispy_layout_mixin import form_actions from materia.models import TipoMateriaLegislativa from sapl.utils import RANGE_ANOS @@ -22,6 +25,11 @@ NATUREZA_PROCESSO = [('0', 'Administrativo'), ('', 'Ambos')] +def get_range_anos(): + return [('', 'Selecione')] \ + + [(year, year) for year in range(date.today().year, 1960, -1)] + + class HorizontalRadioRenderer(forms.RadioSelect.renderer): def render(self): @@ -30,39 +38,41 @@ class HorizontalRadioRenderer(forms.RadioSelect.renderer): class ProtocoloForm(forms.Form): + YEARS = get_range_anos() + tipo_protocolo = forms.ChoiceField(required=False, - label=_('Tipo de Protocolo'), + label='Tipo de Protocolo', choices=TIPOS_PROTOCOLO, widget=forms.Select( attrs={'class': 'selector'})) numero_protocolo = forms.CharField( - label=_('Número de Protocolo'), required=False) + label='Número de Protocolo', required=False) + ano = forms.ChoiceField(required=False, label='Ano', - choices=RANGE_ANOS, + choices=YEARS, widget=forms.Select( attrs={'class': 'selector'})) - inicial = forms.DateField(label=_('Data Inicial'), + inicial = forms.DateField(label='Data Inicial', required=False, widget=forms.TextInput( attrs={'class': 'dateinput'})) - final = forms.DateField(label=_('Data Final'), required=False, + final = forms.DateField(label='Data Final', required=False, widget=forms.TextInput( attrs={'class': 'dateinput'})) natureza_processo = forms.ChoiceField(required=False, - label=_('Natureza Processo'), - choices=NATUREZA_PROCESSO, - # widget=forms.RadioSelect( - # renderer=HorizontalRadioRenderer) - - ) + label='Natureza Processo', + choices=[ + ('0', 'Administrativo'), + ('1', 'Legislativo'), + ('', 'Ambos')]) tipo_documento = forms.ModelChoiceField( - label=_('Tipo de Documento'), + label='Tipo de Documento', required=False, queryset=TipoDocumentoAdministrativo.objects.all(), empty_label='Selecione', @@ -71,18 +81,13 @@ class ProtocoloForm(forms.Form): interessado = forms.CharField(label='Interessado', required=False) tipo_materia = forms.ModelChoiceField( - label=_('Tipo de Matéria'), + label='Tipo de Matéria', required=False, queryset=TipoMateriaLegislativa.objects.all(), empty_label='Selecione', ) - autor = forms.ModelChoiceField( - label='Autor', - required=False, - queryset=Autor.objects.all().order_by('tipo'), - empty_label='Selecione', - ) + autor = forms.CharField(widget=forms.HiddenInput(), required=False) assunto = forms.CharField(label='Assunto', required=False) @@ -102,17 +107,30 @@ class ProtocoloForm(forms.Form): ('tipo_materia', 4)]) row4 = crispy_layout_mixin.to_row( - [('interessado', 4), - ('autor', 4), - ('assunto', 4)]) + [('interessado', 6), + ('assunto', 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)]) + + row6 = crispy_layout_mixin.to_row( [('natureza_processo', 12)]) self.helper = FormHelper() - self.helper.layout = Layout(row1, row2, + self.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'), + row1, row2, row3, row4, - row5, form_actions(save_label='Pesquisar')) + HTML(sapl.utils.autor_label), + HTML(sapl.utils.autor_modal), + row5, + row6, + form_actions(save_label='Pesquisar'))) super(ProtocoloForm, self).__init__( *args, **kwargs) @@ -203,7 +221,7 @@ class ProtocoloDocumentForm(ModelForm): tipo_protocolo = forms.ChoiceField(required=True, label=_('Tipo de Protocolo'), - choices=TIPOS_PROTOCOLO[1:], + choices=TIPOS_PROTOCOLO, widget=forms.RadioSelect( renderer=HorizontalRadioRenderer)) @@ -268,10 +286,10 @@ class ProtocoloDocumentForm(ModelForm): *args, **kwargs) -class ProtocoloMateriaForm(ModelForm): +class ProtocoloMateriaForm(forms.Form): - NUMERACAO_CHOICES = [('1', _('Sequencial por Ano')), - ('2', _('Sequencial Único'))] + NUMERACAO_CHOICES = [('1', 'Sequencial por Ano'), + ('2', 'Sequencial Único')] numeracao = forms.ChoiceField(required=True, choices=NUMERACAO_CHOICES, @@ -280,44 +298,28 @@ class ProtocoloMateriaForm(ModelForm): label='') tipo_protocolo = forms.ChoiceField(required=True, - label=_('Tipo de Protocolo'), - choices=TIPOS_PROTOCOLO[1:], + label='Tipo de Protocolo', + choices=TIPOS_PROTOCOLO, widget=forms.RadioSelect( renderer=HorizontalRadioRenderer)) tipo_materia = forms.ModelChoiceField( - label=_('Tipo de Matéria'), + label='Tipo de Matéria', required=False, queryset=TipoMateriaLegislativa.objects.all(), empty_label='Selecione', ) - num_paginas = forms.CharField(label=_('Núm. Páginas'), required=True) + num_paginas = forms.CharField(label='Núm. Páginas', required=True) ementa = forms.CharField( widget=forms.Textarea, label='Ementa', required=True) - autor = forms.ModelChoiceField( - label='Autor', - required=False, - queryset=Autor.objects.all().order_by('tipo'), - empty_label='Selecione', - ) + autor = forms.CharField(widget=forms.HiddenInput(), required=False) observacao = forms.CharField(required=True, widget=forms.Textarea, label='Observação') - class Meta: - model = Protocolo - fields = ['numeracao', - 'tipo_protocolo', - 'tipo_materia', - 'num_paginas', - 'ementa', - 'autor', - 'observacao', - ] - def __init__(self, *args, **kwargs): row1 = crispy_layout_mixin.to_row( @@ -327,22 +329,29 @@ class ProtocoloMateriaForm(ModelForm): ('tipo_protocolo', 4), ('num_paginas', 4)]) row3 = crispy_layout_mixin.to_row( - [('ementa', 12)]) + [('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'), 2)]) row4 = crispy_layout_mixin.to_row( - [('autor', 12)]) - row5 = crispy_layout_mixin.to_row( [('observacao', 12)]) + row5 = crispy_layout_mixin.to_row( + [('ementa', 12)]) self.helper = FormHelper() self.helper.layout = Layout( Fieldset(_('Protocolo - Opção de Numeração'), row1), Fieldset(_('Identificação da Matéria'), row2, + HTML(sapl.utils.autor_label), + HTML(sapl.utils.autor_modal), row3, row4, row5, - HTML(" "), - form_actions(save_label=_('Protocolar Matéria')) + form_actions(save_label='Protocolar Matéria') ) ) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index f1299ae6d..4c1bd8f6a 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -279,12 +279,14 @@ class ProtocoloMateriaView(FormView): form_class = ProtocoloMateriaForm form_valid_message = _('Matéria cadastrada com sucesso!') + def get_success_url(self): + return reverse('protocolo') + def post(self, request, *args, **kwargs): form = ProtocoloMateriaForm(request.POST) if form.is_valid(): - if request.POST['numeracao'] == '1': numeracao = Protocolo.objects.filter( ano=date.today().year).aggregate(Max('numero')) @@ -310,16 +312,13 @@ class ProtocoloMateriaView(FormView): protocolo.numero_paginas = request.POST['num_paginas'] protocolo.observacao = sub( ' ', ' ', strip_tags(request.POST['observacao'])) - protocolo.save() - return self.form_valid(form) else: return self.form_invalid(form) -# TODO: move to Proposicao app - +# TODO: move to Proposicao app class ProposicaoReceberView(TemplateView): template_name = "protocoloadm/proposicao_receber.html" diff --git a/templates/protocoloadm/protocolo_list.html b/templates/protocoloadm/protocolo_list.html index 56b32c0a7..0957bcdf9 100644 --- a/templates/protocoloadm/protocolo_list.html +++ b/templates/protocoloadm/protocolo_list.html @@ -4,7 +4,7 @@ {% load static %} {% block detail_content %} -{% if protocolos %} +{% if protocolos %} @@ -23,10 +23,10 @@ Data Protocolo: {{ p.data|date:"d/m/Y" }} - Horário: {{ p.timestamp|date:"H:m:s" }}
Interessado: {{ p.interessado }}
Natureza do Processo: - {% if p.tipo_protocolo == 0 %} - Administrativo - {% elif p.tipo_protocolo == 1 %} - Matéria Legislativa + {% if p.tipo_processo == 0 %} + Administrativo + {% elif p.tipo_processo == 1 %} + Matéria Legislativa {% endif %}
Classificação: {{ p.tipo_documento }}

@@ -38,4 +38,4 @@ {% else %}

Nenhum Registro recuperado

{% endif %} -{% endblock detail_content %} \ No newline at end of file +{% endblock detail_content %}

Resultados