Browse Source

Refatora cadastro de materia (formulário normal e simplificado)

pull/249/head
Edward Ribeiro 9 years ago
committed by Eduardo Edson Batista Cordeiro Alves
parent
commit
42cabab459
  1. 46
      materia/views.py

46
materia/views.py

@ -6,13 +6,13 @@ from string import ascii_letters, digits
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail from django.core.mail import send_mail
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse, reverse_lazy
from django.http.response import HttpResponseRedirect from django.http.response import HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.template import Context, loader from django.template import Context, loader
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 ListView, TemplateView from django.views.generic import CreateView, ListView, TemplateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from vanilla.views import GenericView from vanilla.views import GenericView
@ -58,50 +58,16 @@ unidade_tramitacao_crud = Crud(UnidadeTramitacao, 'unidade_tramitacao')
tramitacao_crud = Crud(Tramitacao, '') tramitacao_crud = Crud(Tramitacao, '')
class FormularioSimplificadoView(FormMixin, GenericView): class FormularioSimplificadoView(CreateView):
template_name = "materia/formulario_simplificado.html" template_name = "materia/formulario_simplificado.html"
form_class = FormularioSimplificadoForm form_class = FormularioSimplificadoForm
success_url = reverse_lazy('materialegislativa:list')
def get_success_url(self):
return reverse('materialegislativa:list')
def get(self, request, *args, **kwargs):
form = FormularioSimplificadoForm()
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
form = FormularioSimplificadoForm(request.POST)
if form.is_valid():
materia = form.save(commit=False)
if 'texto_original' in request.FILES:
materia.texto_original = request.FILES['texto_original']
materia.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
return self.render_to_response({'form': form})
class FormularioCadastroView(FormMixin, GenericView): class FormularioCadastroView(CreateView):
template_name = "materia/formulario_cadastro.html" template_name = "materia/formulario_cadastro.html"
form_class = FormularioCadastroForm form_class = FormularioCadastroForm
success_url = reverse_lazy('formulario_cadastro')
def get(self, request, *args, **kwargs):
form = FormularioCadastroForm()
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
form = FormularioCadastroForm(request.POST)
if form.is_valid():
form.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
def get_success_url(self):
return reverse('formulario_cadastro')
class MateriaAnexadaView(FormMixin, GenericView): class MateriaAnexadaView(FormMixin, GenericView):

Loading…
Cancel
Save