From 41b1a10d3a00fedebf748f6a4b4eb479b4d0cffb Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 7 Mar 2016 12:13:44 -0300 Subject: [PATCH] =?UTF-8?q?Refatora=20cadastro=20de=20materia=20(formul?= =?UTF-8?q?=C3=A1rio=20normal=20e=20simplificado)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/views.py | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/materia/views.py b/materia/views.py index 3076f41b1..eeb4e2bee 100644 --- a/materia/views.py +++ b/materia/views.py @@ -6,13 +6,13 @@ from string import ascii_letters, digits from django.contrib import messages from django.core.exceptions import ObjectDoesNotExist 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.shortcuts import redirect from django.template import Context, loader from django.utils.html import strip_tags 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 vanilla.views import GenericView @@ -58,50 +58,16 @@ unidade_tramitacao_crud = Crud(UnidadeTramitacao, 'unidade_tramitacao') tramitacao_crud = Crud(Tramitacao, '') -class FormularioSimplificadoView(FormMixin, GenericView): +class FormularioSimplificadoView(CreateView): template_name = "materia/formulario_simplificado.html" form_class = FormularioSimplificadoForm - - 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}) + success_url = reverse_lazy('materialegislativa:list') -class FormularioCadastroView(FormMixin, GenericView): +class FormularioCadastroView(CreateView): template_name = "materia/formulario_cadastro.html" form_class = FormularioCadastroForm - - 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') + success_url = reverse_lazy('formulario_cadastro') class MateriaAnexadaView(FormMixin, GenericView):