Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. class CandidateCreateProfileView(AnonymousRequiredMixin, FormView):
  2. form_class = CandidateCreateProfileForm
  3. template_name = 'users/candidate_create_profile.html'
  4. success_url = reverse_lazy('account_login')
  5.  
  6. def dispatch(self, request, *args, **kwargs):
  7. activation_key = self.kwargs['activation_key']
  8. self.user = get_object_or_404(User, activation_key=activation_key)
  9.  
  10. if self.user.key_expires < timezone.now():
  11. return render_to_response('users/candidate_confirm_expired.html')
  12. if self.user.is_active:
  13. return HttpResponseRedirect(reverse_lazy('account_login'))
  14.  
  15. return super(CandidateCreateProfileView, self).dispatch(
  16. request, *args, **kwargs)
  17.  
  18. def get_initial(self):
  19. initial = super(CandidateCreateProfileView, self).get_initial()
  20. initial['name'] = self.user.name
  21. initial['mobile_phone'] = self.user.mobile_phone
  22. return initial
  23.  
  24. def form_valid(self, form):
  25. self.user.name = form.cleaned_data['name']
  26. self.user.mobile_phone = form.cleaned_data['mobile_phone']
  27. self.user.notification_type = form.cleaned_data['notification_type']
  28. self.user.set_password(form.cleaned_data['password'])
  29. self.user.is_active = True
  30. self.user.save()
  31.  
  32. return super(CandidateCreateProfileView, self).form_valid(form)
  33.  
  34. class User(models.Model):
  35. name = models.CharField(max_length=50)
  36. ...
  37. def create_candidate_profile(self, name, mobile_phone, notification_type, password):
  38. self.name = name
  39. self.mobile_phone= mobile_phone
  40. self.notification_type=notification_type
  41. self.set_password(password)
  42. self.is_active = True
  43. self.save()
  44.  
  45. def form_valid(self, form):
  46. self.user.create_candidate_profile(
  47. name = form.cleaned_data['name'],
  48. mobile_phone = form.cleaned_data['mobile_phone'],
  49. notification_type = form.cleaned_data['notification_type'],
  50. password = form.cleaned_data['password']
  51. )
  52. return super(CandidateCreateProfileView, self).form_valid(form)
  53.  
  54. User.create_candidate_profile(
  55. name, mobile_phone, notification_type, password
  56. )
  57.  
  58. activation_key = self.kwargs['activation_key']
  59.  
  60. activation_key = self.kwargs.get('activation_key', 'deafult value')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement