Forms

Abstract forms meant to be inherited or concrete forms meant to be used direction in your views.

Note

These forms are unnecessary starting in Django 2.1, as Django now supports custom user models in its own forms.

UserCreationForm

class improved_user.forms.UserCreationForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]

Bases: improved_user.forms.AbstractUserCreationForm

Form to create an unprivileged user

A concrete implementation of AbstractUserCreationForm that uses an e-mail address as a user’s identifier.

Parameters
  • email (EmailField) – Email address

  • full_name (CharField) – Full name

  • short_name (CharField) – Short name

  • password1 (CharField) – Password

  • password2 (CharField) – Enter the same password as above, for verification.

clean_email()[source]

Clean email; set nice error message

Since User.email is unique, this check is redundant, but it sets a nicer error message than the ORM. See #13147.

https://code.djangoproject.com/ticket/13147

property media

Return all media required to render the widgets on this form.

UserChangeForm

class improved_user.forms.UserChangeForm(*args, **kwargs)[source]

Bases: improved_user.forms.AbstractUserChangeForm

Form to update user, but not their password

Parameters
  • password (ReadOnlyPasswordHashField) – Raw passwords are not stored, so there is no way to see this user’s password, but you can change the password using this form.

  • last_login (DateTimeField) – Last login

  • is_superuser (BooleanField) – Designates that this user has all permissions without explicitly assigning them.

  • groups (ModelMultipleChoiceField) – The groups this user belongs to. A user will get all permissions granted to each of their groups.

  • user_permissions (ModelMultipleChoiceField) – Specific permissions for this user.

  • is_staff (BooleanField) – Designates whether the user can log into the admin site.

  • is_active (BooleanField) – Designates whether this user should be treated as active. Unselect this instead of deleting accounts.

  • date_joined (DateTimeField) – Date joined

  • full_name (CharField) – Full name

  • short_name (CharField) – Short name

  • email (EmailField) – Email address

property media

Return all media required to render the widgets on this form.

AbstractUserCreationForm

class improved_user.forms.AbstractUserCreationForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]

Bases: django.forms.models.ModelForm

Abstract Form to create an unprivileged user

Create a User with no permissions based on username and password.

Parameters
  • password1 (CharField) – Password

  • password2 (CharField) – Enter the same password as above, for verification.

_post_clean()[source]

Run password validaton after clean methods

When clean methods are run, the user instance does not yet exist. To properly compare model values agains the password (in the UserAttributeSimilarityValidator), we wait until we have an instance to compare against.

https://code.djangoproject.com/ticket/28127 https://github.com/django/django/pull/8408

Has no effect in Django prior to 1.9 May become unnecessary in Django 2.0 (if this superclass changes)

clean_password2()[source]

Check wether password 1 and password 2 are equivalent

While ideally this would be done in clean, there is a chance a superclass could declare clean and forget to call super. We therefore opt to run this password mismatch check in password2 clean, but to show the error above password1 (as we are unsure whether password 1 or password 2 contains the typo, and putting it above password 2 may lead some users to believe the typo is in just one).

property media

Return all media required to render the widgets on this form.

save(commit=True)[source]

Save the user; use password hasher to set password

AbstractUserChangeForm

class improved_user.forms.AbstractUserChangeForm(*args, **kwargs)[source]

Bases: django.forms.models.ModelForm

Base form update User, but not their password

Parameters

password (ReadOnlyPasswordHashField) – Raw passwords are not stored, so there is no way to see this user’s password, but you can change the password using this form.

clean_password()[source]

Change user info; not the password

We seek to change the user, but not the password. Regardless of what the user provides, return the initial value. This is done here, rather than on the field, because the field does not have access to the initial value

get_local_password_path()[source]

Return relative path to password form

Will return rel_password_url attribute on form or else ‘../password/’. If subclasses cannot simply replace rel_password_url, then they can override this method instead of __init__.

property media

Return all media required to render the widgets on this form.