djblets.integrations.forms¶
Forms for configuring integrations.
- class IntegrationConfigForm(integration: Integration, request: HttpRequest, *args, **kwargs)[source]¶
Bases:
KeyValueForm
Base class for an integration settings form.
This makes it easy to provide a basic form for manipulating the settings of an integration configuration. It takes care of loading/saving the values and prompting the user for a name.
Integrations should subclass this and provide additional fields that they want to display to the user. They must provide a
Meta
class containing the fieldsets they want to display.Applications can subclass this to provide additional special fields that should be made available to integrations. Integrations would then need to subclass that specialized form. Applications that want to do this will likely need to modify
model_fields
.- model_fields = ('name', 'enabled')[source]¶
A list of fields on the model that should not be saved in settings.
- basic_info_fieldset = (None, {'fields': ('name', 'enabled'), 'description': 'Start by giving this configuration a name so you can easily identify it later. You can also mark this configuration as enabled or disabled.'})[source]¶
The fieldset containing basic information on the configuration.
Subclasses can override this to provide additional fields, styling, or a description.
- instance: Optional[BaseIntegrationConfig]¶
The integration configuration being updated.
This will be
None
if creating a new configuration.
- __init__(integration: Integration, request: HttpRequest, *args, **kwargs) None [source]¶
Initialize the form.
- Parameters:
integration (
djblets.integrations.integration.Integration
) – The integration being configured.request (
django.http.HttpRequest
) – The HTTP request from the client.*args (
tuple
) – Positional arguments to pass to the form.**kwargs (
dict
) – Keyword arguments to pass to the form.
- integration: Integration¶
The integration being configured.
- request: HttpRequest¶
The HTTP request used for the form.
- classmethod build_fieldsets() None [source]¶
Build the fieldsets used for the configuration form.
By default, this will prepend
basic_info_fieldset
to the existing list of fieldsets onMeta
(if any).Subclasses can override this to provide more specialized customization of the form. Since this is working on a form class and not an instance, they should be careful to apply changes only once.
- property config: Optional[BaseIntegrationConfig][source]¶
The configuration that’s being edited.
If this is a brand new configuration, this will be
None
until saved.Any value will be an instance of the subclass of
BaseIntegrationConfig
provided by the application supporting integrations.
- get_key_value(key: str, default: Optional[object] = None) object [source]¶
Return the value for a key.
This will first look for the value from the
BaseIntegrationConfig
, and will then fall back to looking for the value in the configuration’ssettings
field.This is used internally by the parent class, and is not meant to be used directly.
- set_key_value(key: str, value: Optional[object]) None [source]¶
Set the value for a key.
This will first look for the key to set in the
BaseIntegrationConfig
. If it’s there, that field’s value will be set. Otherwise, it will fall back to setting the key in the configuration’ssettings
field.This is used internally by the parent class, and is not meant to be used directly.
- __annotations__ = {'instance': 'Optional[BaseIntegrationConfig]', 'integration': 'Integration', 'request': 'HttpRequest'}¶
- create_instance() BaseIntegrationConfig [source]¶
Create an instance of a configuration.
This is used internally by the parent class, and is not meant to be called by consumers of the form.
- Returns:
A new integration configuration.
- Return type:
- declared_fields = {'enabled': <django.forms.fields.BooleanField object>, 'name': <django.forms.fields.CharField object>}¶