Browse Source

Fix qa_check related alerts

pull/7/head
Edward Ribeiro 9 years ago
parent
commit
d4c164805b
  1. 8
      protocoloadm/urls.py
  2. 38
      protocoloadm/views.py

8
protocoloadm/urls.py

@ -1,7 +1,6 @@
from django.conf.urls import include, url from django.conf.urls import include, url
from protocoloadm.views import (ProtocoloPesquisaView,
#anular_protocolo_crud, from protocoloadm.views import (AnularProtocoloAdmView, ProtocoloPesquisaView,
AnularProtocoloAdmView,
documento_acessorio_administrativo_crud, documento_acessorio_administrativo_crud,
documento_administrativo_crud, documento_administrativo_crud,
protocolo_documento_crud, protocolo_documento_crud,
@ -28,6 +27,7 @@ urlpatterns = [
# url(r'^protocoloadm/anular-protocolo/', # url(r'^protocoloadm/anular-protocolo/',
# include(anular_protocolo_crud.urls), name='anular_protocolo'), # include(anular_protocolo_crud.urls), name='anular_protocolo'),
url(r'^protocoladm/anular-protocolo', AnularProtocoloAdmView.as_view(), name='anular_protocolo'), url(r'^protocoladm/anular-protocolo',
AnularProtocoloAdmView.as_view(), name='anular_protocolo'),
] ]

38
protocoloadm/views.py

@ -1,22 +1,13 @@
from datetime import datetime from datetime import datetime
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
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 ListView, TemplateView
from django.views.generic import ListView
from django.views.generic import View
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.edit import UpdateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from django.core.exceptions import ObjectDoesNotExist
from django.utils.html import strip_tags
from materia.models import TipoMateriaLegislativa from materia.models import TipoMateriaLegislativa
from sapl.crud import build_crud from sapl.crud import build_crud
@ -202,8 +193,10 @@ class ProtocoloPesquisaView(TemplateView, FormMixin):
else: else:
return self.form_invalid(form) return self.form_invalid(form)
class AnularProcoloAdmForm(forms.Form): class AnularProcoloAdmForm(forms.Form):
numero_protocolo = forms.CharField(label='Número de Protocolo', required=True) numero_protocolo = forms.CharField(
label='Número de Protocolo', required=True)
ano = forms.CharField(label='Ano', required=True) ano = forms.CharField(label='Ano', required=True)
motivo = forms.CharField(label='Motivo', required=True) motivo = forms.CharField(label='Motivo', required=True)
@ -214,11 +207,12 @@ def get_client_ip(request):
ip = x_forwarded_for.split(',')[0] ip = x_forwarded_for.split(',')[0]
else: else:
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
return ip return ip
class AnularProtocoloAdmView(FormMixin, TemplateView): class AnularProtocoloAdmView(FormMixin, TemplateView):
template_name = 'protocoloadm/anular_protocoloadm.html' template_name = 'protocoloadm/anular_protocoloadm.html'
def get_success_url(self): def get_success_url(self):
return reverse('anular_protocolo') return reverse('anular_protocolo')
@ -229,19 +223,21 @@ class AnularProtocoloAdmView(FormMixin, TemplateView):
form = AnularProcoloAdmForm(request.POST) form = AnularProcoloAdmForm(request.POST)
if form.is_valid(): if form.is_valid():
numero = request.POST['numero_protocolo'] numero = request.POST['numero_protocolo']
ano = request.POST['ano_protocolo'] ano = request.POST['ano_protocolo']
justificativa_anulacao = strip_tags(request.POST['justificativa_anulacao']) justificativa_anulacao = strip_tags(
user_anulacao = "NOUSER" # TODO get user from session request.POST['justificativa_anulacao'])
user_anulacao = "NOUSER" # TODO get user from session
ip_addr = get_client_ip(request) ip_addr = get_client_ip(request)
try: try:
protocolo = Protocolo.objects.get(numero = numero, ano = ano) protocolo = Protocolo.objects.get(numero=numero, ano=ano)
if protocolo.anulado: if protocolo.anulado:
form._errors = {'error_message': 'Procolo encontra-se anulado'} form._errors = {
'error_message': 'Procolo encontra-se anulado'}
return self.form_invalid(form) return self.form_invalid(form)
protocolo.anulado = True protocolo.anulado = True
@ -251,9 +247,9 @@ class AnularProtocoloAdmView(FormMixin, TemplateView):
protocolo.save() protocolo.save()
return self.form_valid(form) return self.form_valid(form)
except ObjectDoesNotExist: except ObjectDoesNotExist:
form._errors = {'error_message': 'Protocolo não existe'} form._errors = {'error_message': 'Protocolo não existe'}
return self.form_invalid(form) return self.form_invalid(form)
else: else:
return self.form_invalid(form) return self.form_invalid(form)

Loading…
Cancel
Save