Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. class Seeker(models.Model):
  2. user = models.OneToOneField(User)
  3. birthday = models.DateField()
  4. name = models.CharField(max_length=100)
  5.  
  6. def __unicode__(self):
  7. return self.name
  8.  
  9. class RegistrationForm(ModelForm):
  10. username = forms.CharField(label = (u'User Name'))
  11. email = forms.EmailField(label =(u'Email Address'))
  12. password = forms.CharField(label = (u'Password'),widget = forms.PasswordInput(render_value = False))
  13. password1 = forms.CharField(label =(u'Verify Password'),widget = forms.PasswordInput(render_value = False))
  14.  
  15. class Meta:
  16. model = Seeker
  17. exclude = ('user',)
  18.  
  19. def clean_username(self):
  20. username = self.cleaned_data['username']
  21. try:
  22. User.objects.get(username = username)
  23. except User.DoesNotExist:
  24. return username
  25.  
  26. raise forms.ValidationError("That username is already taken,please select another.")
  27.  
  28. def clean(self):
  29.  
  30. if self.cleaned_data['password'] != self.cleaned_data['password1']:
  31. raise forms.ValidationError("The Password did not match please try again.")
  32. return self.cleaned_data
  33.  
  34. def SeekersRegistration(request):
  35. if request.user.is_authenticated():
  36. return HttpResponseRedirect('/profile/')
  37. if request.method == "POST":
  38. form = RegistrationForm(request.POST)
  39. if form.is_valid():
  40. user = User.objects.create_user(username = form.cleaned_data['username'], email = form.cleaned_data['email'], password =form.cleaned_data['password'])
  41. user.save()
  42. seekers = Seeker(user =user, name = form.cleaned_data['name'],birthday = form.cleaned_data['birthday'])
  43. seekers.save()
  44. return HttpResponseRedirect('/profile/')
  45. else:
  46. return render_to_response('register.html',{'form':form},context_instance = RequestContext(request))
  47. else:
  48. '''user is not submitting the form, show them a blank registration form'''
  49. form = RegistrationForm()
  50. context = {'form':form}
  51. return render_to_response('register.html',context,context_instance = RequestContext(request))
  52.  
  53. from django.contrib.auth.models import User
  54. from django.db.models.signals import post_save
  55. from django.dispatch import receiver
  56.  
  57. @receiver(post_save, sender=User)
  58. def add_user_to_specific_group(instance, created, **kwargs):
  59. if created:
  60. # assign user to group
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement