from django.utils.translation import ugettext_lazy as _
from models import ActivationProfile
A form that creates a user, with no privileges, from the given username and password.
help_text = _("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
error_message = _("This value must contain only letters, numbers and underscores."))
email = forms.EmailField(label=_("Email address"))
- password = forms.CharField(label=_("Password"), required=False,
- help_text = _("Leave blank to create a user with a random password and an activation profile. \
- Only use this if you want to set up an account with a known password"))
+ password1 = forms.CharField(label=_("Password"),
+ help_text = _("Leave blank to create a user with "
+ "a random password and an activation profile. Only "
+ "use this if you want to set up an account with a "
+ password2 = forms.CharField(label=_("Password confirmation"),
+ help_text = _("Enter the same password as above, "
email_user = forms.BooleanField(initial=True, label=_("Send the user a notification email"), required=False,
help_text = _("If you generate a random password, this will be an email with an activation link. Otherwise it will contain the users login credentials"))
+ fields = ("username", "email", "email_user")
""" Validates that the username is alphanumeric and not already in use. """
username = self.cleaned_data["username"]
raise forms.ValidationError(_("A user with that email address already exists."))
+ def clean_password2(self):
+ password1 = self.cleaned_data.get("password1", "")
+ password2 = self.cleaned_data["password2"]
+ if password1 != password2:
+ raise forms.ValidationError(_("The two password fields didn't match."))
+ def save(self, *args, **kwargs):
""" Creates a normal new user and return that, or creates an inactive user with an activation profile. """
send_email = self.cleaned_data["email_user"]
if self.cleaned_data["password"] == '': # a activation profile needs to be created