Example #1
0
 def save(self, commit=True):
     user = super(CustomUserCreationForm, self).save(commit=False)
     user.set_password(self.cleaned_data["password1"])
     # if the username is a mailaddress
     if re.match(r"^[a-zA-Z0-9!#$%&*+/=?^_`{|}~-][email protected][a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$", user.username):
         user.email = user.username
         # extract the username from the mailaddress
         username = user.username.split("@", 1)[0]  # take the part before the @ in the mail address as username
         username = username.replace(".", "_")
         # if this username would already exist, add roman numbers until this is not the case
         if not user.isValidUserName(username):
             # the username/userslug does already exist
             index = 2
             while True:
                 username = "{} {}".format(username, int_to_roman(index))
                 if user.isValidUserName(username):
                     break
                 index += 1
         user.username = username
     else:
         user.email = ""
     if commit:
         user.save()
     return user
Example #2
0
 def version_roman(self):
     return int_to_roman(self.version)