djblets.avatars.forms¶
Forms for Djblets’ avatar support.
- class AvatarServiceConfigForm(*args, **kwargs)¶
Bases:
ConfigPageForm
An avatar service configuration form.
- js_view_class: Optional[str] = 'Djblets.Avatars.ServiceSettingsFormView'¶
The optional Backbone view used to render the form.
- template_name = 'avatars/service_form.html'¶
The template used to render the form.
- avatar_service_id = None¶
The avatar service ID of the associated service.
- __init__(*args, **kwargs)¶
Initialize the configuration form.
- Parameters:
- Keyword Arguments:
configuration (
dict
) – The current configurationservice (
djblets.avatars.services.base.AvatarService
) – The avatar service instance that instantiated this form.
- get_extra_context()¶
Return extra rendering context.
- Returns:
Extra rendering context.
- Return type:
- __annotations__ = {'css_bundle_names': 'List[str]', 'form_id': 'Optional[str]', 'form_title': 'Optional[StrOrPromise]', 'js_bundle_names': 'List[str]', 'js_model_class': 'Optional[str]', 'js_view_class': 'Optional[str]', 'save_label': 'Optional[StrOrPromise]'}¶
- declared_fields = {'form_target': <django.forms.fields.CharField object>}¶
- class AvatarSettingsForm(*args, **kwargs)¶
Bases:
ConfigPageForm
The avatar settings form.
This allows users to select the avatar service they wish to use and, if necessary, configure it (e.g., by uploading an avatar).
- form_id: Optional[str] = 'avatar'¶
The unique ID of the form.
This must be unique across all ConfigPages at a given URL.
- form_title: Optional[StrOrPromise] = 'Avatar'¶
The displayed title for the form.
- js_view_class: Optional[str] = 'Djblets.Avatars.SettingsFormView'¶
The optional Backbone view used to render the form.
- js_model_class: Optional[str] = 'Djblets.Avatars.Settings'¶
The optional Backbone model used for the configuration form state.
- template_name = 'avatars/settings_form.html'¶
The template used to render the form.
- avatar_service_registry = None¶
The avatar service registry. Subclasses must override this.
- property is_multipart¶
Whether or not the form is multi-part.
The form is multi-part when there is an enabled avatar service that has a multi-part configuration form.
- Returns:
Whether or not the form is multi-part.
- Return type:
- property js_bundle_names¶
Yield the bundle names necessary.
Each avatar service can specify a configuration form that may specify JS bundles. Since those forms are not registered through the page, we must add them this way.
- Yields:
unicode
– The names of the JS bundles to load on the page.
- property css_bundle_names¶
Yield the CSS bundle names.
Each avatar service can specify a configuration form that may specify CSS bundles. Since those forms are not registered through the page, we must add them this way.
- Yields:
unicode
– The names of the CSS bundles to load on the page.
- __init__(*args, **kwargs)¶
Initialize the form.
- clean_avatar_service_id()¶
Clean the avatar_service_id field.
This ensures that the value corresponds to a valid and enabled avatar service.
- Returns:
The avatar service ID.
- Return type:
- Raises:
django.core.exceptions.ValidationError – Raised when the avatar service ID is invalid.
- clean()¶
Clean the form.
This will clean the avatar service configuration form of the selected avatar service (if it is configurable) and raise an exception if it is not valid.
This will cache any sub-form errors so that they can be rendered to the user when rendering the form.
- Returns:
The form’s cleaned data.
- Return type:
- Raises:
ValidationError – Raised when the form for the selected avatar service is invalid.
- save()¶
Save the avatar settings.
This method attempts to save
- get_extra_context()¶
Return the extra context for rendering the form.
- Returns:
The extra rendering context.
- Return type:
- get_js_model_data()¶
Return the JS model data for the form.
- Returns:
A dictionary of the model data for the form.
- Return type:
- __annotations__ = {'css_bundle_names': 'List[str]', 'form_id': 'Optional[str]', 'form_title': 'Optional[StrOrPromise]', 'js_bundle_names': 'List[str]', 'js_model_class': 'Optional[str]', 'js_view_class': 'Optional[str]', 'save_label': 'Optional[StrOrPromise]'}¶
- declared_fields = {'avatar_service_id': <django.forms.fields.ChoiceField object>, 'form_target': <django.forms.fields.CharField object>}¶