Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CandidateCreateProfileView(AnonymousRequiredMixin, FormView):
- form_class = CandidateCreateProfileForm
- template_name = 'users/candidate_create_profile.html'
- success_url = reverse_lazy('account_login')
- def dispatch(self, request, *args, **kwargs):
- activation_key = self.kwargs['activation_key']
- self.user = get_object_or_404(User, activation_key=activation_key)
- if self.user.key_expires < timezone.now():
- return render_to_response('users/candidate_confirm_expired.html')
- if self.user.is_active:
- return HttpResponseRedirect(reverse_lazy('account_login'))
- return super(CandidateCreateProfileView, self).dispatch(
- request, *args, **kwargs)
- def get_initial(self):
- initial = super(CandidateCreateProfileView, self).get_initial()
- initial['name'] = self.user.name
- initial['mobile_phone'] = self.user.mobile_phone
- return initial
- def form_valid(self, form):
- self.user.name = form.cleaned_data['name']
- self.user.mobile_phone = form.cleaned_data['mobile_phone']
- self.user.notification_type = form.cleaned_data['notification_type']
- self.user.set_password(form.cleaned_data['password'])
- self.user.is_active = True
- self.user.save()
- return super(CandidateCreateProfileView, self).form_valid(form)
- class User(models.Model):
- name = models.CharField(max_length=50)
- ...
- def create_candidate_profile(self, name, mobile_phone, notification_type, password):
- self.name = name
- self.mobile_phone= mobile_phone
- self.notification_type=notification_type
- self.set_password(password)
- self.is_active = True
- self.save()
- def form_valid(self, form):
- self.user.create_candidate_profile(
- name = form.cleaned_data['name'],
- mobile_phone = form.cleaned_data['mobile_phone'],
- notification_type = form.cleaned_data['notification_type'],
- password = form.cleaned_data['password']
- )
- return super(CandidateCreateProfileView, self).form_valid(form)
- User.create_candidate_profile(
- name, mobile_phone, notification_type, password
- )
- activation_key = self.kwargs['activation_key']
- activation_key = self.kwargs.get('activation_key', 'deafult value')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement