Browse Source

Add Anular Protocolo

pull/7/head
Edward Ribeiro 9 years ago
parent
commit
18b2afa833
  1. 11
      protocoloadm/urls.py
  2. 81
      protocoloadm/views.py
  3. 28
      templates/protocoloadm/anular_protocoloadm.html
  4. 2
      templates/protocoloadm/protocoloadm_detail.html

11
protocoloadm/urls.py

@ -1,5 +1,7 @@
from django.conf.urls import include, url
from protocoloadm.views import (ProtocoloPesquisaView, anular_protocolo_crud,
from protocoloadm.views import (ProtocoloPesquisaView,
#anular_protocolo_crud,
AnularProtocoloAdmView,
documento_acessorio_administrativo_crud,
documento_administrativo_crud,
protocolo_documento_crud,
@ -21,8 +23,11 @@ urlpatterns = [
url(r'^protocoloadm/protocolo-doc/',
include(protocolo_documento_crud.urls)),
url(r'^protocoloadm/protocolo-mat/', include(protocolo_materia_crud.urls)),
url(r'^protocoloadm/anular-protocolo/',
include(anular_protocolo_crud.urls)),
url(r'^protocoloadm/protocolo$',
ProtocoloPesquisaView.as_view(), name='protocolo'),
# url(r'^protocoloadm/anular-protocolo/',
# include(anular_protocolo_crud.urls), name='anular_protocolo'),
url(r'^protocoladm/anular-protocolo', AnularProtocoloAdmView.as_view(), name='anular_protocolo'),
]

81
protocoloadm/views.py

@ -3,9 +3,20 @@ from datetime import datetime
from django import forms
from django.core.urlresolvers import reverse
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.edit import UpdateView
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 sapl.crud import build_crud
@ -85,13 +96,13 @@ protocolo_materia_crud = build_crud(
[('observacao', 12)]],
])
anular_protocolo_crud = build_crud(
Protocolo, '', [
# anular_protocolo_crud = build_crud(
# Protocolo, '', [
[_('Indentificação do Protocolo'),
[('numero', 6), ('ano', 6)],
[('justificativa_anulacao', 12)]],
])
# [_('Indentificação do Protocolo'),
# [('numero', 6), ('ano', 6)],
# [('justificativa_anulacao', 12)]],
# ])
class ProtocoloForm(forms.Form):
@ -107,7 +118,7 @@ class ProtocoloForm(forms.Form):
interessado = forms.CharField(label='Interessado', required=False)
tipo_materia = forms.CharField(label='Tipo de Matéria', required=False)
autor = forms.CharField(label='Autor', required=False)
assunto = forms.CharField(label='Assunto <DFS', required=False)
assunto = forms.CharField(label='Assunto', required=False)
class ProtocoloPesquisaView(TemplateView, FormMixin):
@ -190,3 +201,59 @@ class ProtocoloPesquisaView(TemplateView, FormMixin):
)
else:
return self.form_invalid(form)
class AnularProcoloAdmForm(forms.Form):
numero_protocolo = forms.CharField(label='Número de Protocolo', required=True)
ano = forms.CharField(label='Ano', required=True)
motivo = forms.CharField(label='Motivo', required=True)
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
class AnularProtocoloAdmView(FormMixin, TemplateView):
template_name = 'protocoloadm/anular_protocoloadm.html'
def get_success_url(self):
return reverse('anular_protocolo')
def get(self, request, *args, **kwargs):
return self.render_to_response({})
def post(self, request, *args, **kwargs):
form = AnularProcoloAdmForm(request.POST)
if form.is_valid():
numero = request.POST['numero_protocolo']
ano = request.POST['ano_protocolo']
justificativa_anulacao = strip_tags(request.POST['justificativa_anulacao'])
user_anulacao = "NOUSER" # TODO get user from session
ip_addr = get_client_ip(request)
try:
protocolo = Protocolo.objects.get(numero = numero, ano = ano)
if protocolo.anulado:
form._errors = {'error_message': 'Procolo encontra-se anulado'}
return self.form_invalid(form)
protocolo.anulado = True
protocolo.justificativa_anulacao = justificativa_anulacao
protocolo.user_anulacao = user_anulacao
protocolo.ip_anulacao = ip_addr
protocolo.save()
return self.form_valid(form)
except ObjectDoesNotExist:
form._errors = {'error_message': 'Protocolo não existe'}
return self.form_invalid(form)
else:
return self.form_invalid(form)

28
templates/protocoloadm/anular_protocoloadm.html

@ -0,0 +1,28 @@
{% extends "protocoloadm/protocoloadm_detail.html" %}
{% load i18n %}
{% block detail_content %}
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<p> {{ errors }} </p>
{% endfor %}
{% endfor %}
{% endif %}
<form method="POST">
{% csrf_token %}
<fieldset>
Número / Ano
<input type="text" id="numero_protocolo" name="numero_protocolo" /> /
<input type="text" id="ano_protocolo" name="ano_protocolo" />
</br>
Motivo da Anulação
<textarea id="justificativa_anulacao" name="justificativa_anulacao">
</textarea>
</br>
<input type="submit" value="Anular" class="button primary" />
</fieldset>
</form>
{% endblock detail_content %}

2
templates/protocoloadm/protocoloadm_detail.html

@ -6,6 +6,6 @@
<dd><a href="./protocolo" class="button secondary">{% trans 'Inicio' %}</a></dd>
<dd><a href="./protocolo-doc" class="button secondary">{% trans 'Protocolar Documento' %}</a></dd>
<dd><a href="./protocolo-mat" class="button secondary">{% trans 'Protocolar Matéria' %}</a></dd>
<dd><a href="./anular-protocolo" class="button secondary">{% trans 'Anular Protocolo' %}</a></dd>
<dd><a href="{% url 'anular_protocolo' %}" class="button secondary">{% trans 'Anular Protocolo' %}</a></dd>
</dl>
{% endblock sections_nav %}

Loading…
Cancel
Save