From 23af22079ad3a4ecd406372676b0d3723b755e8f Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 16 Mar 2016 10:39:42 -0300 Subject: [PATCH 1/4] Refatora anular protocolo --- protocoloadm/views.py | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 6153d9481..66ea618b7 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -115,39 +115,30 @@ class ProtocoloListView(ListView): return context -class AnularProtocoloAdmView(FormView): +class AnularProtocoloAdmView(CreateView): template_name = 'protocoloadm/anular_protocoloadm.html' form_class = AnularProcoloAdmForm - success_url = reverse_lazy('anular_protocolo') form_valid_message = _('Protocolo anulado com sucesso!') + def get_success_url(self): + return reverse('protocolo') + def get_initial(self): initial_data = {} initial_data['user_anulacao'] = self.request.user.username initial_data['ip_anulacao'] = get_client_ip(self.request) - initial_data['anulado'] = True return initial_data - def post(self, request, *args, **kwargs): - - form = AnularProcoloAdmForm(request.POST) - - if form.is_valid(): - - numero = form.cleaned_data['numero'] - ano = form.cleaned_data['ano'] - - protocolo = Protocolo.objects.get(numero=numero, ano=ano) - protocolo.anulado = True - protocolo.justificativa_anulacao = sub(' ', ' ', strip_tags( - form.cleaned_data['justificativa_anulacao'])) - protocolo.user_anulacao = form.cleaned_data['user_anulacao'] - protocolo.ip_anulacao = form.cleaned_data['ip_anulacao'] - protocolo.save() - - return self.form_valid(form) - else: - return self.form_invalid(form) + def form_valid(self, form): + protocolo = Protocolo.objects.get(numero=form.cleaned_data['numero'], + ano=form.cleaned_data['ano']) + protocolo.anulado = True + protocolo.justificativa_anulacao = ( + form.cleaned_data['justificativa_anulacao']) + protocolo.user_anulacao = form.cleaned_data['user_anulacao'] + protocolo.ip_anulacao = form.cleaned_data['ip_anulacao'] + protocolo.save() + return redirect(self.get_success_url()) class ProtocoloDocumentoView(FormValidMessageMixin, FormView): From a44d88d8c22d75d3d77c1181b8972bc2aff9084c Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 16 Mar 2016 10:56:23 -0300 Subject: [PATCH 2/4] Refatora protocolar documento --- protocoloadm/views.py | 66 ++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 66ea618b7..5cded887b 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -141,52 +141,36 @@ class AnularProtocoloAdmView(CreateView): return redirect(self.get_success_url()) -class ProtocoloDocumentoView(FormValidMessageMixin, FormView): - +class ProtocoloDocumentoView(FormValidMessageMixin, CreateView): template_name = "protocoloadm/protocolar_documento.html" form_class = ProtocoloDocumentForm - success_url = reverse_lazy('protocolo') form_valid_message = _('Protocolo cadastrado com sucesso!') - def post(self, request, *args, **kwargs): - - form = ProtocoloDocumentForm(request.POST) - - if form.is_valid(): - if form.cleaned_data['numeracao'] == '1': - numeracao = Protocolo.objects.filter( - ano=date.today().year).aggregate(Max('numero')) - elif form.cleaned_data['numeracao'] == '2': - numeracao = Protocolo.objects.all().aggregate(Max('numero')) - # else: - # raise ValidationError(_("Campo numeração é obrigatório")) - - if numeracao['numero__max'] is None: - numeracao['numero__max'] = 0 - - protocolo = form.save(commit=False) - protocolo.numero = numeracao['numero__max'] + 1 - protocolo.ano = datetime.now().year - protocolo.data = datetime.now().strftime("%Y-%m-%d") - protocolo.hora = datetime.now().strftime("%H:%M") - protocolo.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M") - protocolo.tipo_protocolo = request.POST['tipo_protocolo'] - protocolo.tipo_processo = '0' # TODO validar o significado - protocolo.interessado = request.POST['interessado'] - protocolo.anulado = False - protocolo.tipo_documento = TipoDocumentoAdministrativo.objects.get( - id=request.POST['tipo_documento']) - protocolo.assunto_ementa = sub( - ' ', ' ', strip_tags(request.POST['assunto'])) - protocolo.numero_paginas = request.POST['num_paginas'] - protocolo.observacao = sub( - ' ', ' ', strip_tags(request.POST['observacao'])) - - protocolo.save() + def get_success_url(self): + return reverse('protocolo') - return self.form_valid(form) - else: - return self.form_invalid(form) + def form_valid(self, form): + f = form.save(commit=False) + + if form.cleaned_data['numeracao'] == '1': + numeracao = Protocolo.objects.filter( + ano=date.today().year).aggregate(Max('numero')) + elif form.cleaned_data['numeracao'] == '2': + numeracao = Protocolo.objects.all().aggregate(Max('numero')) + + if numeracao['numero__max'] is None: + numeracao['numero__max'] = 0 + + f.tipo_processo = '0' # TODO validar o significado + f.anulado = False + f.numero = numeracao['numero__max'] + 1 + f.ano = datetime.now().year + f.data = datetime.now().strftime('%Y-%m-%d') + f.hora = datetime.now().strftime('%H:%M') + f.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M") + + f.save() + return redirect(self.get_success_url()) class CriarDocumentoProtocolo(CreateView): From 82fe8e88c4b0fc46a384fed8ea472d21bc4a13eb Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 17 Mar 2016 09:30:12 -0300 Subject: [PATCH 3/4] Refatora protocolar documento --- protocoloadm/forms.py | 42 +++++++++++++++--------------- protocoloadm/views.py | 60 +++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 53 deletions(-) diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index 81ac2dfb8..e9571e2c2 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -17,6 +17,7 @@ from sapl.utils import RANGE_ANOS from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, TipoDocumentoAdministrativo, TramitacaoAdministrativo) +from materia.models import Autor TIPOS_PROTOCOLO = [('0', 'Enviado'), ('1', 'Recebido')] @@ -286,7 +287,7 @@ class ProtocoloDocumentForm(ModelForm): *args, **kwargs) -class ProtocoloMateriaForm(forms.Form): +class ProtocoloMateriaForm(ModelForm): NUMERACAO_CHOICES = [('1', 'Sequencial por Ano'), ('2', 'Sequencial Único')] @@ -303,22 +304,26 @@ class ProtocoloMateriaForm(forms.Form): widget=forms.RadioSelect( renderer=HorizontalRadioRenderer)) - tipo_materia = forms.ModelChoiceField( - 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) - ementa = forms.CharField( - widget=forms.Textarea, label='Ementa', required=True) + autor = forms.IntegerField(widget=forms.HiddenInput(), required=False) - autor = forms.CharField(widget=forms.HiddenInput(), required=False) + def clean_autor(self): + data_autor = self.cleaned_data['autor'] + try: + autor = Autor.objects.get(id=data_autor) + except ObjectDoesNotExist: + data_autor = None + else: + data_autor = autor + return data_autor - observacao = forms.CharField(required=True, - widget=forms.Textarea, - label='Observação') + class Meta: + model = Protocolo + fields = ['numeracao', + 'tipo_protocolo', + 'tipo_materia', + 'numero_paginas', + 'autor', + 'observacao'] def __init__(self, *args, **kwargs): @@ -327,7 +332,7 @@ class ProtocoloMateriaForm(forms.Form): row2 = crispy_layout_mixin.to_row( [('tipo_materia', 4), ('tipo_protocolo', 4), - ('num_paginas', 4)]) + ('numero_paginas', 4)]) row3 = crispy_layout_mixin.to_row( [('autor', 0), (Button('pesquisar', @@ -335,11 +340,9 @@ class ProtocoloMateriaForm(forms.Form): css_class='btn btn-primary btn-sm'), 2), (Button('limpar', 'limpar Autor', - css_class='btn btn-primary btn-sm'), 2)]) + css_class='btn btn-primary btn-sm'), 10)]) row4 = crispy_layout_mixin.to_row( [('observacao', 12)]) - row5 = crispy_layout_mixin.to_row( - [('ementa', 12)]) self.helper = FormHelper() self.helper.layout = Layout( @@ -350,7 +353,6 @@ class ProtocoloMateriaForm(forms.Form): HTML(sapl.utils.autor_modal), row3, row4, - row5, form_actions(save_label='Protocolar Matéria') ) ) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 5cded887b..4e8e560b4 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -249,7 +249,7 @@ class ComprovanteProtocoloView(TemplateView): return context -class ProtocoloMateriaView(FormView): +class ProtocoloMateriaView(CreateView): template_name = "protocoloadm/protocolar_materia.html" form_class = ProtocoloMateriaForm @@ -258,40 +258,34 @@ class ProtocoloMateriaView(FormView): def get_success_url(self): return reverse('protocolo') - def post(self, request, *args, **kwargs): + def form_valid(self, form): + if self.request.POST['numeracao'] == '1': + numeracao = Protocolo.objects.filter( + ano=date.today().year).aggregate(Max('numero')) + else: + numeracao = Protocolo.objects.all().aggregate(Max('numero')) - form = ProtocoloMateriaForm(request.POST) + if numeracao is None: + numeracao['numero__max'] = 0 - if form.is_valid(): - if request.POST['numeracao'] == '1': - numeracao = Protocolo.objects.filter( - ano=date.today().year).aggregate(Max('numero')) - else: - numeracao = Protocolo.objects.all().aggregate(Max('numero')) - - if numeracao is None: - numeracao['numero__max'] = 0 - - protocolo = Protocolo() - - protocolo.numero = numeracao['numero__max'] + 1 - protocolo.ano = datetime.now().year - protocolo.data = datetime.now().strftime("%Y-%m-%d") - protocolo.hora = datetime.now().strftime("%H:%M") - protocolo.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M") - protocolo.tipo_protocolo = request.POST['tipo_protocolo'] - protocolo.tipo_processo = '0' # TODO validar o significado - protocolo.autor = Autor.objects.get(id=request.POST['autor']) - protocolo.anulado = False - protocolo.tipo_materia = TipoMateriaLegislativa.objects.get( - id=request.POST['tipo_materia']) - 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) + protocolo = Protocolo() + + protocolo.numero = numeracao['numero__max'] + 1 + protocolo.ano = datetime.now().year + protocolo.data = datetime.now().strftime("%Y-%m-%d") + protocolo.hora = datetime.now().strftime("%H:%M") + protocolo.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M") + protocolo.tipo_protocolo = self.request.POST['tipo_protocolo'] + protocolo.tipo_processo = '0' # TODO validar o significado + if form.cleaned_data['autor']: + protocolo.autor = form.cleaned_data['autor'] + protocolo.anulado = False + protocolo.tipo_materia = TipoMateriaLegislativa.objects.get( + id=self.request.POST['tipo_materia']) + protocolo.numero_paginas = self.request.POST['numero_paginas'] + protocolo.observacao = self.request.POST['observacao'] + protocolo.save() + return redirect(self.get_success_url()) # TODO: move to Proposicao app From e75dff4b9931da02bd6c6e59b495ba96cc9e8828 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 17 Mar 2016 09:52:09 -0300 Subject: [PATCH 4/4] Muda nome de variave --- protocoloadm/forms.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index e9571e2c2..eee1f450b 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -307,14 +307,14 @@ class ProtocoloMateriaForm(ModelForm): autor = forms.IntegerField(widget=forms.HiddenInput(), required=False) def clean_autor(self): - data_autor = self.cleaned_data['autor'] + autor_field = self.cleaned_data['autor'] try: - autor = Autor.objects.get(id=data_autor) + autor = Autor.objects.get(id=autor_field) except ObjectDoesNotExist: - data_autor = None + autor_field = None else: - data_autor = autor - return data_autor + autor_field = autor + return autor_field class Meta: model = Protocolo