Users
Forms for creating and modifying user objects
Authentication Form
- class integreat_cms.cms.forms.users.authentication_form.AuthenticationForm(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, field_order=None, use_required_attribute=None, renderer=None)[source]
Bases:
Form
Form to check the password of an already authenticated user. Used for critical operations where a valid session might not be enough (e.g. modifying 2-FA options).
Form fields:
password
: Password (CharField
)
- __init__(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, field_order=None, use_required_attribute=None, renderer=None)[source]
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean()[source]
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
Organization Field
- class integreat_cms.cms.forms.users.organization_field.OrganizationField(queryset, *, empty_label='---------', required=True, widget=None, label=None, initial=None, help_text='', to_field_name=None, limit_choices_to=None, blank=False, **kwargs)[source]
Bases:
ModelChoiceField
ModelChoiceField which puts the organization’s region id as data attribute on <options>
- __init__(queryset, *, empty_label='---------', required=True, widget=None, label=None, initial=None, help_text='', to_field_name=None, limit_choices_to=None, blank=False, **kwargs)[source]
- bound_data(data, initial)[source]
Return the value that should be shown for this field on render of a bound form, given the submitted POST data for the field and the initial data, if any.
For most fields, this will simply be data; FileFields need to handle it a bit differently.
- clean(value)[source]
Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.
- default_error_messages = {'invalid_choice': 'Select a valid choice. That choice is not one of the available choices.'}[source]
- get_bound_field(form, field_name)[source]
Return a BoundField instance that will be used when accessing the form field in a template.
- get_limit_choices_to()[source]
Return
limit_choices_to
for this form field.If it is a callable, invoke it and return the result.
alias of
HiddenInput
- label_from_instance(obj: Organization) dict[str, Any] [source]
Normally, this function convert objects into strings and generate the labels for the choices presented by this object.
In this case, we abuse the function also to pass the organization’s region id to the
create_option()
function to enable it to use it as data attribute.- Parameters:
obj (Organization) – The name of the option
- Returns:
A dict of the real label and the organization’s region id
- Return type:
- widget[source]
The widget to use when rendering this type of Field.
alias of
OrganizationFieldWidget
- class integreat_cms.cms.forms.users.organization_field.OrganizationFieldWidget(attrs=None, choices=())[source]
Bases:
Select
Select widget which puts the organization’s region id as data attribute on <options>
- create_option(name: str, value: ModelChoiceIteratorValue | str, label: dict[str, Any] | str, selected: bool, index: int, subindex: Any | None = None, attrs: dict[str, str] | None = None) dict[str, Any] [source]
This function creates an option which can be selected in the organization field
- Parameters:
name (str) – The name of the option
value (ModelChoiceIteratorValue | str) – the value of the option (the page id)
label (dict[str, Any] | str) – The label (and optionally the region id) of the option
selected (bool) – Whether or not the option is selected
index (int) – The index of the option
subindex (Any | None) – The subindex of the option
attrs (dict[str, str] | None) – The attributes of the option
- Returns:
The option dict
- Return type:
- id_for_label(id_, index='0')[source]
Use an incremented id for each option where the main widget references the zero index.
- subwidgets(name, value, attrs=None)[source]
Yield all “subwidgets” of this widget. Used to enable iterating options from a BoundField for choice widgets.
- use_required_attribute(initial)[source]
Don’t render ‘required’ if the first <option> has a value, as that’s invalid HTML.
Password Reset Form
- class integreat_cms.cms.forms.users.password_reset_form.CustomPasswordResetForm(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, field_order=None, use_required_attribute=None, renderer=None)[source]
Bases:
PasswordResetForm
A custom form to attach the logo to the password reset email
Form fields:
email
: Email (EmailField
)
- __init__(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, field_order=None, use_required_attribute=None, renderer=None)[source]
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean()[source]
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
- get_users(email)[source]
Given an email, return matching user(s) who should receive a reset.
This allows subclasses to more easily customize the default policies that prevent inactive users and users with unusable passwords from resetting their password.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
- save(domain_override=None, subject_template_name='registration/password_reset_subject.txt', email_template_name='registration/password_reset_email.html', use_https=False, token_generator=<django.contrib.auth.tokens.PasswordResetTokenGenerator object>, from_email=None, request=None, html_email_template_name=None, extra_email_context=None)[source]
Generate a one-use only link for resetting password and send it to the user.
- send_mail(subject_template_name: str, email_template_name: str, context: dict[str, Any], from_email: Any | None, to_email: str, html_email_template_name: str) None [source]
Send a django.core.mail.EmailMultiAlternatives to to_email.
- Parameters:
subject_template_name (str) – The template to be used to render the subject of the email
email_template_name (str) – The template to be used to render the text email
from_email (Any | None) – The email address of the sender
to_email (str) – The email address of the recipient
html_email_template_name (str) – The template to be used to render the HTML email
- Return type:
None
Passwordless Authentication Form
- class integreat_cms.cms.forms.users.passwordless_authentication_form.PasswordlessAuthenticationForm(*args: Any, request: HttpRequest | None = None, **kwargs: Any)[source]
Bases:
Form
Form class for authenticating users without using passwords but other authentication methods like FIDO2.
Form fields:
username
: Username (UsernameField
)
- Parameters:
args (Any)
request (HttpRequest | None)
kwargs (Any)
- __init__(*args: Any, request: HttpRequest | None = None, **kwargs: Any) None [source]
Render passwordless authentication form for HTTP GET requests
- Parameters:
request (HttpRequest | None) – Object representing the user call
*args (Any) – The supplied arguments
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean()[source]
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- clean_username() str [source]
Checks the input of the user to enable authentication
- Raises:
ValidationError – If the given username or email is invalid
- Returns:
The cleaned username
- Return type:
- error_messages = {'disabled': 'Your account is not activated for passwordless authentication. Please use the default login.', 'inactive': 'This account is inactive.', 'invalid_login': 'The username or email address is incorrect.', 'not_available': 'In order to use passwordless authentication, you have to configure at least one 2-factor authentication method.'}[source]
The different reasons why passwordless authentication might not be possible
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
Region User Form
- class integreat_cms.cms.forms.users.region_user_form.RegionUserForm(region: Region, **kwargs: Any)[source]
Bases:
UserForm
Form for creating and modifying region user objects
Form fields:
username
: Username (CharField
)first_name
: First name (CharField
)last_name
: Last name (CharField
)email
: Email address (EmailField
)is_active
: Active (BooleanField
)role
: Role (ModelChoiceField
)send_activation_link
: Send activation link (BooleanField
)organization
: Organization (ModelChoiceField
)expert_mode
: Experienced user (BooleanField
)staff_role
: Team (ModelChoiceField
)password
: Password (CharField
)
- Parameters:
region (Region)
kwargs (Any)
- __init__(region: Region, **kwargs: Any) None [source]
Initialize region user form
- Parameters:
region (Region) – The current region
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_error_messages(request: HttpRequest) None [source]
This function accepts the current request and adds the form’s error messages to the message queue of
django.contrib.messages
.- Parameters:
request (HttpRequest) – The current request submitting the form
- Return type:
None
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean() dict[str, Any] [source]
Validate form fields which depend on each other, see
django.forms.Form.clean()
- clean_email() str [source]
Make the email lower case (see Overriding the clean() method)
- Returns:
The email in lower case
- Return type:
- get_error_messages() list[dict[str, str]] [source]
Return all error messages of this form and append labels to field-errors
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
- save(commit: bool = True) User [source]
This method extends the default
save()
-method of the baseModelForm
to set attributes which are not directly determined by input fields.
User Email Form
- class integreat_cms.cms.forms.users.user_email_form.UserEmailForm(**kwargs: Any)[source]
Bases:
CustomModelForm
Form for modifying user email addresses
Form fields:
email
: Email address (EmailField
)
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize placeholder model form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Raises:
TypeError – If form is instantiated directly without an inheriting subclass
- Return type:
None
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_error_messages(request: HttpRequest) None [source]
This function accepts the current request and adds the form’s error messages to the message queue of
django.contrib.messages
.- Parameters:
request (HttpRequest) – The current request submitting the form
- Return type:
None
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean() dict[str, Any] [source]
This method extends the default
clean()
-method of the baseModelForm
to provide debug logging- Returns:
The cleaned data (see Overriding the clean() method)
- Return type:
- get_error_messages() list[dict[str, str]] [source]
Return all error messages of this form and append labels to field-errors
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
- save(commit: bool = True) Any [source]
This method extends the default
save()
-method of the baseModelForm
to provide debug logging- Parameters:
commit (bool) – Whether or not the changes should be written to the database
- Returns:
The saved object returned by The save() method
- Return type:
Any
User Filter Form
- class integreat_cms.cms.forms.users.user_filter_form.UserFilterForm(**kwargs: Any)[source]
Bases:
CustomFilterForm
Form for filtering user objects
Form fields:
role
: Role (ChoiceField
)permissions
: Permissions (ChoiceField
)region
: Region (ModelChoiceField
)query
: Query (CharField
)
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize the custom filter form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- apply(users: QuerySet[User]) QuerySet[User] [source]
Filter the users list according to the given filter data
- clean()[source]
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- filter_by_query(users: QuerySet[User]) QuerySet[User] [source]
Filter the pages list by a given search query
- property filters_visible: bool[source]
This function determines whether the filter form is visible by default.
- Returns:
Whether any filters (other than search) were changed
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- property is_enabled: bool[source]
This function determines whether the filters are applied.
- Returns:
Whether filtering should be performed
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
User Form
- class integreat_cms.cms.forms.users.user_form.UserForm(**kwargs: Any)[source]
Bases:
CustomModelForm
Form for creating and modifying user objects
Form fields:
username
: Username (CharField
)first_name
: First name (CharField
)last_name
: Last name (CharField
)email
: Email address (EmailField
)is_staff
: Staff status (BooleanField
)is_active
: Active (BooleanField
)is_superuser
: Superuser status (BooleanField
)organization
: Organization (OrganizationField
)expert_mode
: Experienced user (BooleanField
)regions
: Regions (ModelMultipleChoiceField
)role
: Role (ModelChoiceField
)send_activation_link
: Send activation link (BooleanField
)passwordless_authentication_enabled
: Enable passwordless authentication (BooleanField
)staff_role
: Team (ModelChoiceField
)password
: Password (CharField
)
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize user form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Return type:
None
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_error_messages(request: HttpRequest) None [source]
This function accepts the current request and adds the form’s error messages to the message queue of
django.contrib.messages
.- Parameters:
request (HttpRequest) – The current request submitting the form
- Return type:
None
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean() dict[str, Any] [source]
Validate form fields which depend on each other, see
django.forms.Form.clean()
- clean_email() str [source]
Make the email lower case (see Overriding the clean() method)
- Returns:
The email in lower case
- Return type:
- get_error_messages() list[dict[str, str]] [source]
Return all error messages of this form and append labels to field-errors
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
- save(commit: bool = True) User [source]
This method extends the default
save()
-method of the baseModelForm
to set attributes which are not directly determined by input fields.
User Password Form
- class integreat_cms.cms.forms.users.user_password_form.UserPasswordForm(**kwargs: Any)[source]
Bases:
CustomModelForm
Form for changing a user’s password
Form fields:
old_password
: My old password (CharField
)new_password
: My new password (CharField
)new_password_confirm
: Confirm my new password (CharField
)
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize placeholder model form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Raises:
TypeError – If form is instantiated directly without an inheriting subclass
- Return type:
None
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_error_messages(request: HttpRequest) None [source]
This function accepts the current request and adds the form’s error messages to the message queue of
django.contrib.messages
.- Parameters:
request (HttpRequest) – The current request submitting the form
- Return type:
None
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean() dict[str, Any] [source]
Validate form fields which depend on each other, see
django.forms.Form.clean()
- get_error_messages() list[dict[str, str]] [source]
Return all error messages of this form and append labels to field-errors
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
- save(commit: bool = True) User [source]
This method extends the default
save()
-method of the baseModelForm
to set attributes which are not directly determined by input fields.
User Preferences Form
- class integreat_cms.cms.forms.users.user_preferences_form.UserPreferencesForm(**kwargs: Any)[source]
Bases:
CustomModelForm
Form for changing a user’s preferences
Form fields:
distribute_sidebar_boxes
: Automatically distribute sidebar boxes (BooleanField
)
- Parameters:
kwargs (Any)
- __init__(**kwargs: Any) None [source]
Initialize placeholder model form
- Parameters:
**kwargs (Any) – The supplied keyword arguments
- Raises:
TypeError – If form is instantiated directly without an inheriting subclass
- Return type:
None
- add_error(field, error)[source]
Update the content of self._errors.
The field argument is the name of the field to which the errors should be added. If it’s None, treat the errors as NON_FIELD_ERRORS.
The error argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. An “error” can be either a simple string or an instance of ValidationError with its message attribute set and a “list or dictionary” can be an actual list or dict or an instance of ValidationError with its error_list or error_dict attribute set.
If error is a dictionary, the field argument must be None and errors will be added to the fields that correspond to the keys of the dictionary.
- add_error_messages(request: HttpRequest) None [source]
This function accepts the current request and adds the form’s error messages to the message queue of
django.contrib.messages
.- Parameters:
request (HttpRequest) – The current request submitting the form
- Return type:
None
- add_initial_prefix(field_name)[source]
Add an ‘initial’ prefix for checking dynamic initial values.
- add_prefix(field_name)[source]
Return the field name with a prefix appended, if this Form has a prefix set.
Subclasses may wish to override.
- clean() dict[str, Any] [source]
This method extends the default
clean()
-method of the baseModelForm
to provide debug logging- Returns:
The cleaned data (see Overriding the clean() method)
- Return type:
- get_error_messages() list[dict[str, str]] [source]
Return all error messages of this form and append labels to field-errors
- get_initial_for_field(field, field_name)[source]
Return initial data for field on form. Use initial data from the form or the field, in that order. Evaluate callable values.
Return a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.
- is_multipart()[source]
Return True if the form needs to be multipart-encoded, i.e. it has FileInput, or False otherwise.
- non_field_errors()[source]
Return an ErrorList of errors that aren’t associated with a particular field – i.e., from Form.clean(). Return an empty ErrorList if there are none.
- order_fields(field_order)[source]
Rearrange the fields according to field_order.
field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. If field_order is None, keep all fields in the order defined in the class. Ignore unknown fields in field_order to allow disabling fields in form subclasses without redefining ordering.
- save(commit: bool = True) Any [source]
This method extends the default
save()
-method of the baseModelForm
to provide debug logging- Parameters:
commit (bool) – Whether or not the changes should be written to the database
- Returns:
The saved object returned by The save() method
- Return type:
Any