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
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.
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
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
A form that creates a user, with no privileges, from the given 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).
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.