Base support for configuration forms.
ConfigPageForm(page, request, user, *args, **kwargs)¶
Base class for a form on a ConfigPage.
Consumers can subclass ConfigPageForm and register it on a
djblets.configforms.pages.ConfigPage. It will be shown whenever the user navigates to that page.
A form will generally be shown as a box with a title and a save button, though this is customizable.
The unique ID of the form.
This must be unique across all ConfigPages at a given URL.
The displayed title for the form.
The label for the save button.
This can be set to
Noneto disable the button.
The template used to render the form.
The list of CSS bundle names to include on the page.
The optional Backbone model used for the configuration form state.
The optional Backbone view used to render the form.
__init__(page, request, user, *args, **kwargs)¶
Initialize the form.
- page (ConfigPage) – The page this form resides on.
- request (HttpRequest) – The HTTP request from the client.
- user (User) – The user who is viewing the page.
The current user’s profile.
Deprecated since version 1.0.4: Callers should not depend on this being around. Instead, they should query for the profile and set it themselves if they need one.
Set the initial fields for the form based on provided data.
This can be used during
load()to fill in the fields based on data from the database or another source.
Parameters: field_values (dict) – The initial field data to set on the form.
Return whether the form should be visible.
This can be overridden to hide forms based on certain criteria.
Trueif the form should be rendered on the page (default), or
Return type: bool
js_model_classis provided, the data returned from this function will be provided to the model when constructed.
Returns: A dictionary of attributes to pass to the Model instance. By default, it will be empty. Return type: dict
js_view_classis provided, the data returned from this function will be provided to the view when constructed.
Returns: A dictionary of options to pass to the View instance. By default, it will be empty. Return type: dict
Render the form to a string.
template_namewill be used to render the form. The template will be passed
form(this form’s instance) and
Subclasses can override this to provide additional rendering logic.
Returns: The rendered form as HTML. Return type: unicode
Return extra rendering context.
Subclasses can override this to provide additional rendering context.
Returns: The additional rendering context. By default, it is empty. Return type: dict
Load data for the form.
By default, this does nothing. Subclasses can override this to load data into the fields based on data from the database or from another source.