Browse Source

Refatora Anular Protocolo

pull/248/head
Edward Ribeiro 9 years ago
parent
commit
adae222343
  1. 1
      comissoes/views.py
  2. 21
      protocoloadm/views.py

1
comissoes/views.py

@ -21,7 +21,6 @@ comissao_crud = Crud(Comissao, 'modulo_comissoes')
class CadastrarComissaoView(CreateView): class CadastrarComissaoView(CreateView):
template_name = "comissoes/cadastrar_comissao.html" template_name = "comissoes/cadastrar_comissao.html"
form_class = CadastrarComissaoForm form_class = CadastrarComissaoForm
success_url = reverse_lazy('comissao:list') success_url = reverse_lazy('comissao:list')

21
protocoloadm/views.py

@ -1,6 +1,7 @@
from datetime import date, datetime from datetime import date, datetime
from re import sub from re import sub
from braces.views import FormValidMessageMixin
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
@ -9,7 +10,7 @@ from django.http import HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, DetailView, ListView, FormView from django.views.generic import CreateView, DetailView, FormView, ListView
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from vanilla import GenericView from vanilla import GenericView
@ -122,6 +123,7 @@ class ProtocoloListView(ListView):
page_obj.number, paginator.num_pages) page_obj.number, paginator.num_pages)
return context return context
def get_client_ip(request): def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for: if x_forwarded_for:
@ -131,16 +133,11 @@ def get_client_ip(request):
return ip return ip
class AnularProtocoloAdmView(FormMixin, GenericView): class AnularProtocoloAdmView(FormValidMessageMixin, FormView):
template_name = 'protocoloadm/anular_protocoloadm.html' template_name = 'protocoloadm/anular_protocoloadm.html'
form_class = AnularProcoloAdmForm form_class = AnularProcoloAdmForm
success_url = reverse_lazy('anular_protocolo')
def get_success_url(self): form_valid_message = _('Protocolo anulado com sucesso!')
return reverse('anular_protocolo')
def get(self, request, *args, **kwargs):
form = AnularProcoloAdmForm()
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
@ -163,7 +160,7 @@ class AnularProtocoloAdmView(FormMixin, GenericView):
errors = form._errors.setdefault( errors = form._errors.setdefault(
forms.forms.NON_FIELD_ERRORS, forms.forms.NON_FIELD_ERRORS,
forms.util.ErrorList()) forms.util.ErrorList())
errors.append(_("Procolo %s/%s já encontra-se anulado") errors.append(_("Protocolo %s/%s já encontra-se anulado")
% (numero, ano)) % (numero, ano))
return self.form_invalid(form) return self.form_invalid(form)
@ -177,7 +174,7 @@ class AnularProtocoloAdmView(FormMixin, GenericView):
except ObjectDoesNotExist: except ObjectDoesNotExist:
errors = form._errors.setdefault( errors = form._errors.setdefault(
forms.forms.NON_FIELD_ERRORS, forms.util.ErrorList()) forms.forms.NON_FIELD_ERRORS, forms.util.ErrorList())
errors.append(_("Procolo %s/%s não existe" % (numero, ano))) errors.append(_("Protocolo %s/%s não existe" % (numero, ano)))
return self.form_invalid(form) return self.form_invalid(form)
else: else:
return self.form_invalid(form) return self.form_invalid(form)
@ -201,7 +198,7 @@ class ProtocoloDocumentoView(FormMixin, GenericView):
form = ProtocoloDocumentForm(request.POST) form = ProtocoloDocumentForm(request.POST)
if form.is_valid(): if form.is_valid():
if request.POST['numeracao'] == '1': if form.cleaned_data['numeracao'] == '1':
numeracao = Protocolo.objects.filter( numeracao = Protocolo.objects.filter(
ano=date.today().year).aggregate(Max('numero')) ano=date.today().year).aggregate(Max('numero'))
else: else:

Loading…
Cancel
Save