- def save(self, profile_callback = None):
- user = RegistrationProfile.objects.create_inactive_user( \
- username = self.cleaned_data['username'],
- password = self.cleaned_data['password'],
- email = self.cleaned_data['email'],
- profile_callback = profile_callback)
- user.first_name = self.cleaned_data.get('first_name', '')
- user.last_name = self.cleaned_data.get('last_name', '')
- user.save()
-
- # saving the userprofile causes the firstname/lastname to propagate
- # to the person objects.
- user.get_profile().save()
-
- return user
+ def clean_username(self):
+ value = self.cleaned_data['username']
+ try:
+ user = User.objects.get(username__iexact = value)
+ except User.DoesNotExist:
+ return self.cleaned_data['username']
+ raise forms.ValidationError('This username is already taken. ' + \
+ 'Please choose another.')
+
+ def clean_email(self):
+ value = self.cleaned_data['email']
+ try:
+ user = User.objects.get(email__iexact = value)
+ except User.DoesNotExist:
+ return self.cleaned_data['email']
+ raise forms.ValidationError('This email address is already in use ' + \
+ 'for the account "%s".\n' % user.username)