Browse Source

Refactor anular protocolo and fix silly url bug

pull/11/merge
Edward Ribeiro 9 years ago
parent
commit
3bcd81066f
  1. 2
      protocoloadm/urls.py
  2. 7
      protocoloadm/views.py
  3. 2
      templates/protocoloadm/anular_protocoloadm.html

2
protocoloadm/urls.py

@ -27,7 +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', url(r'^protocoloadm/anular-protocolo',
AnularProtocoloAdmView.as_view(), name='anular_protocolo'), AnularProtocoloAdmView.as_view(), name='anular_protocolo'),
] ]

7
protocoloadm/views.py

@ -3,6 +3,7 @@ from datetime import datetime
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 from django.core.urlresolvers import reverse
from django.shortcuts import render
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.base import TemplateView from django.views.generic.base import TemplateView
@ -233,6 +234,8 @@ class AnularProtocoloAdmView(FormMixin, TemplateView):
form = AnularProcoloAdmForm(request.POST) form = AnularProcoloAdmForm(request.POST)
template_name = reverse("anular_protocolo")
if form.is_valid(): if form.is_valid():
numero = request.POST['numero_protocolo'] numero = request.POST['numero_protocolo']
@ -259,7 +262,9 @@ class AnularProtocoloAdmView(FormMixin, TemplateView):
protocolo.ip_anulacao = ip_addr protocolo.ip_anulacao = ip_addr
protocolo.save() protocolo.save()
return self.form_valid(form) message = "Protocolo criado com sucesso"
return render(request, self.template_name, {'form': form, 'message': message})
except ObjectDoesNotExist: except ObjectDoesNotExist:
errors = form._errors.setdefault( errors = form._errors.setdefault(

2
templates/protocoloadm/anular_protocoloadm.html

@ -1,7 +1,7 @@
{% extends "protocoloadm/protocoloadm_detail.html" %} {% extends "protocoloadm/protocoloadm_detail.html" %}
{% load i18n %} {% load i18n %}
{% block detail_content %} {% block detail_content %}
<div>{{ view.message }} </div> <div>{{ message }} </div>
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
<fieldset> <fieldset>

Loading…
Cancel
Save