Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. class CadastroCreateView(CreateView):
  2. form_class = CadastroForm
  3. success_url = '/?cadastro=1'
  4. template_name = 'signup.html'
  5. model = Cadastro
  6.  
  7. def get_context_data(self, **kwargs):
  8. context = super(CadastroCreateView, self).get_context_data(**kwargs)
  9. context.update({
  10. 'estados':U.STATE_CHOICES,
  11. 'culturas':Cultura.objects.all(),
  12. 'interesses': Topico.objects.all(),
  13. })
  14. return context
  15.  
  16. def post(self, request, *args, **kwargs):
  17. """
  18. Handles POST requests, instantiating a form instance and its inline
  19. formsets with the passed POST variables and then checking them for
  20. validity.
  21. """
  22. self.object = None
  23. form_class = self.get_form_class()
  24. form = self.get_form(form_class)
  25.  
  26.  
  27. if (form.is_valid()):
  28. return self.form_valid(form)
  29. else:
  30. return HttpResponse('oi')
  31. return self.form_invalid(form)
  32.  
  33. def form_valid(self, form):
  34. """
  35. Called if all forms are valid. Creates a Recipe instance along with
  36. associated Ingredients and Instructions and then redirects to a
  37. success page.
  38. """
  39. self.object = form.save()
  40. u = authenticate(username=self.object.email, password=self.object.senha)
  41. authlogin(self.request, u)
  42. return redirect('conteudos:home')
  43.  
  44.  
  45. def form_invalid(self, form):
  46. """
  47. Called if a form is invalid. Re-renders the context data with the
  48. data-filled forms and errors.
  49. """
  50. return self.render_to_response(
  51. self.get_context_data(form=form)
  52. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement