reviewboard.scmtools.forms¶
Forms for configuring repositories.
- class HostingAccountWidget(attrs=None, choices=())[source]¶
Bases:
Select
A widget for selecting and modifying an assigned hosting account.
This presents a list of available hosting service accounts as a drop-down, and provides a link for editing the credentials of the selected account.
- __annotations__ = {}¶
- __slotnames__ = []¶
- class BaseRepositorySubForm(*args, **kwargs)[source]¶
Bases:
Form
A sub-form used in the main repository configuration form.
This provides some standard functionality for collecting information needed to configure a specific type of repository (one backed by a particular
SCMTool
orBaseHostingService
). It takes care of basic form customization and loading, and must be subclassed for other operations.Third-parties will never need to subclass this directly. Instead, subclass one of:
Forms can provide a
Meta
class that defineMeta.help_texts
andMeta.labels
attributes. Each is a dictionary mapping field names to new content for those fields. See the classes above for examples.New in version 3.0.16.
- local_site¶
The Local Site that any queries or state should be bound to.
- repository¶
The repository being configured. This is allowed to be
None
, mainly for testing purposes, but will always have a value when constructed byRepositoryForm
.
- __init__(*args, **kwargs)[source]¶
Initialize the form.
Subclasses should use this to alter the fields shown in the form, if needed.
- Parameters:
- Keyword Arguments:
repository (
reviewboard.scmtools.models.Repository
, optional) – The repository that’s being created or updated. This is allowed to beNone
, mainly for testing purposes, but will always have a value when constructed byRepositoryForm
.local_site (
reviewboard.site.models.LocalSite
, optional) – The Local Site that any queries or state should be bound to.
- get_initial_data()[source]¶
Return initial data for the form.
By default, this doesn’t return any initial data. Subclasses can override this to return something suitable for the form.
Generally, sensitive information, like passwords, should not be provided.
- Returns:
Initial data for the form.
- Return type:
- load()[source]¶
Load information for the form.
By default, this will populate initial values returned in
get_initial_data()
. Subclasses can override this to set other fields or state as needed.
- get_field_data_from(obj, field_names=None, model_fields=None, norm_key_func=None)[source]¶
Return data from an object for use in the form’s fields.
This is a utility method that helps load in field data based on the attributes on an object and the object’s
extra_data
field. It’s most commonly going to be used for a subclass’sload()
orget_initial_data()
.- Parameters:
obj (
django.db.models.Model
) – The model object to load data from. This is expected to have anextra_data
field.field_names (
list
ofunicode
, optional) – A specific list of field names to load from the object. If not provided, this defaults to the form’s list of field names. These do not all have to be present in the object.model_fields (
set
ofunicode
, optional) – Names of fields that should be loaded directly from attributes onobj
, instead of the object’sextra_data
.norm_key_func (
callable
, optional) – A function that normalizes a key before looking up in the object’sextra_data
. If not provided, this defaults toadd_prefix()
.
- Returns:
The loaded field data.
- Return type:
- __annotations__ = {}¶
- declared_fields = {}¶
- class BaseRepositoryAuthSubForm(*args, **kwargs)[source]¶
Bases:
BaseRepositorySubForm
Base class for any repository authentication forms.
Third-parties will never need to subclass this directly. Instead, subclass one of:
- __annotations__ = {}¶
- declared_fields = {}¶
- class BaseRepositoryInfoSubForm(*args, **kwargs)[source]¶
Bases:
BaseRepositorySubForm
Base class for any repository information forms.
Third-parties will never need to subclass this directly. Instead, subclass one of:
- __annotations__ = {}¶
- declared_fields = {}¶
- class SCMToolSubFormMixin(**kwargs)[source]¶
Bases:
object
Mixin class for SCMTool-specific subforms.
This should only be used internally. SCMTools will want to subclass
BaseSCMToolAuthForm
,BaseSCMToolRepositoryForm
, or one of their descendents.New in version 3.0.16.
- __init__(**kwargs)[source]¶
Initialize the form.
Subclasses should use this to alter the fields shown in the form, if needed, but not to set initial form field values from the repository, as those will be overridden.
- get_initial_data()[source]¶
Return initial data for the form.
This will load information from the repository’s attributes and
extra_data
into the form’s fields.- Returns:
Initial data for the form.
- Return type:
- class BaseSCMToolAuthForm(**kwargs)[source]¶
Bases:
SCMToolSubFormMixin
,BaseRepositoryAuthSubForm
Base class for SCMTool authentication forms.
This is a blank form that can be subclassed and populated with fields for requesting authentication credentials for plain repositories.
Any cleaned data fields named
username
orpassword
will be set directly on the equivalentRepository
model fields. Any other fields will be stored inRepository.extra_data
, using a key in the form of<scmtoolid>_<fieldname>
.If an SCMTool uses a standard username/password, they’re most likely going to want to use
StandardSCMToolAuthForm
directly or as a parent class.New in version 3.0.16.
- __annotations__ = {}¶
- declared_fields = {}¶
- class BaseSCMToolRepositoryForm(**kwargs)[source]¶
Bases:
SCMToolSubFormMixin
,BaseRepositoryInfoSubForm
Base class for SCMTool repository forms.
This is a blank form that can be subclassed and populated with fields for requesting information for plain repositories.
Subclasses are required to provide a Path field, or to at least provide a suitable value in the cleaned data based on other fields.
Any cleaned data fields named
path
,mirror_path
, orraw_file_url
will be set directly on the equivalentRepository
model fields. Any other fields will be stored inRepository.extra_data
, using a key in the form of<scmtoolid>_<fieldname>
. The exception is the fielduse_ticket_auth
, which will be stored without an SCMTool ID prefix for legacy reasons.If an SCMTool wants to provide standard path/mirror path fields, they’re most likely going to want to use
StandardSCMToolRepositoryForm
directly or as a parent class.New in version 3.0.16.
- __annotations__ = {}¶
- declared_fields = {}¶
- class StandardSCMToolAuthForm(**kwargs)[source]¶
Bases:
BaseSCMToolAuthForm
A standard SCMTool authentication form.
This provides standard Username and Password fields. These are optional by default. Subclasses can override them to make the fields required, remove them, or add additional authentication-related fields.
See the documentation on the
parent class
to see how field data is stored.New in version 3.0.16.
- clean_username()[source]¶
Clean the username field.
This will strip all whitespace from the field before returning it.
- Returns:
The value provided in the field, with whitespace stripped.
- Return type:
- clean_password()[source]¶
Clean the password field.
This will strip all whitespace from the field before returning it.
- Returns:
The value provided in the field, with whitespace stripped.
- Return type:
- __annotations__ = {}¶
- declared_fields = {'password': <django.forms.fields.CharField object>, 'username': <django.forms.fields.CharField object>}¶
- class StandardSCMToolRepositoryForm(**kwargs)[source]¶
Bases:
BaseSCMToolRepositoryForm
A standard SCMTool repository form.
This provides standard Path and Mirror Path fields, as well as optional fields for Raw File URL Mask (if
SCMTool.raw_file_url
is set) and Use ticket-based authentication <ifSCMTool.raw_file_url
is set). These two optional fields are provided for legacy purposes, but will be removed in the future, so subclasses should explicitly provide them if needed.Subclasses can override any of the form’s fields, remove them, or add additional fields needed to identify repositories.
If a Path field is not appropriate for the type of repository, then it’s still up to the subclass to provide a suitable
path
value in the cleaned data that uniquely identifies the repository.See the documentation on the
parent class
to see how field data is stored.New in version 3.0.16.
- __init__(**kwargs)[source]¶
Initialize the form.
This will set the appropriate fields on the form based on the capabilities on the
SCMTool
, as per the class’s documentation.- Parameters:
**kwargs (
dict
) – Additional keyword arguments for the parent form.
- clean_path()[source]¶
Clean the Path field.
This will strip all whitespace from the field before returning it.
- Returns:
The value provided in the field, with whitespace stripped.
- Return type:
- clean_mirror_path()[source]¶
Clean the Mirror Path field.
This will strip all whitespace from the field before returning it.
- Returns:
The value provided in the field, with whitespace stripped.
- Return type:
- clean_raw_file_url()[source]¶
Clean the Raw File URL Mask field.
This will strip all whitespace from the field before returning it.
- Returns:
The value provided in the field, with whitespace stripped.
- Return type:
- __annotations__ = {}¶
- declared_fields = {'mirror_path': <django.forms.fields.CharField object>, 'path': <django.forms.fields.CharField object>, 'raw_file_url': <django.forms.fields.CharField object>, 'use_ticket_auth': <django.forms.fields.BooleanField object>}¶
- class RepositoryForm(data=None, *args, **kwargs)[source]¶
Bases:
LocalSiteAwareModelFormMixin
,ModelForm
A form for creating and updating repositories.
This form provides an interface for creating and updating repositories, handling the association with hosting services, linking accounts, dealing with SSH keys and SSL certificates, and more.
Configuration details are collected primarily through subforms provided by SCMTools and Hosting Services.
- NO_KEY_HELP_FMT = 'This repository type supports SSH key association, but the Review Board server does not have an SSH key. <a href="%s">Add an SSH key.</a>'[source]¶
- __init__(data=None, *args, **kwargs)[source]¶
Initialize the repository configuration form.
This will set up the initial state for the form, locating any tools and hosting services that can be shown and setting up the configuration and authentication forms they provide.
- certerror: Optional[Union[CertificateVerificationError, UnverifiedCertificateError]]¶
A certificate verification exception generated during validation.
- Type:
reviewboard.certs.errors.CertificateVerificationError
or – reviewboard.scmtools.errors.UnverifiedCertificateError
- cert: Optional[Certificate]¶
A legacy certificate accepted from legacy SCMTools.
- Type
reviewboard.scmtools.certs.Certificate
- property local_site_name[source]¶
The name of the current Local Site for this form.
This will be
None
if no Local Site is assigned.
- iter_subforms(bound_only=False, with_auth_forms=False)[source]¶
Iterate through all subforms matching the given criteria.
This allows callers to easily retrieve all the subforms available to the repository form, optionally limiting those to subforms with data bound.
By default, this does not include authentication forms, as those are treated specially and should generally not be operated upon in the same way as repository and bug tracker subforms.
The defaults may change, so callers should be explicit about the results they want.
- Parameters:
- Yields:
django.forms.Form
– Each subform matching the criteria.
- get_repository_already_exists()[source]¶
Return whether a repository with these details already exists.
This will validate the form before returning a result. Callers are encouraged to call
is_valid()
themselves before calling this.- Returns:
True
if a repository already exists with this name or path.False
if one does not exist.- Return type:
- full_clean(*args, **kwargs)[source]¶
Perform a full clean the form.
This wraps the typical form cleaning process by first ensuring that all relation fields limit their choices to objects on the bound Local Site (if one is set), allowing validation to work naturally on each field. It then invokes the standard form cleaning logic, and then restores the choices.
- Returns:
The cleaned data from the form.
- Return type:
- Raises:
django.core.exceptions.ValidationError – The form failed to validate.
- clean()[source]¶
Performs validation on the form.
This will check the form fields for errors, calling out to the various clean_* methods.
It will check the repository path to see if it represents a valid repository and if an SSH key or HTTPS certificate needs to be verified.
This will also build repository and bug tracker URLs based on other fields set in the form.
- clean_bug_tracker_hosting_url()[source]¶
Clean the bug tracker hosting URL.
This will strip all whitespace from the URL.
- Returns:
The hosting URL with whitespace stripped.
- Return type:
- clean_hosting_type()[source]¶
Validates that the hosting type represents a valid hosting service.
This won’t do anything if no hosting service is used.
- clean_bug_tracker_type()[source]¶
Validates that the bug tracker type represents a valid hosting service.
This won’t do anything if no hosting service is used.
- clean_tool()[source]¶
Check the SCMTool used for this repository.
This will ensure the selected SCMTool is valid and that its dependencies all exist.
- Returns:
The Tool model entry to assign to the repository.
- Return type:
- Raises:
django.core.exceptions.ValidationError – The tool was invalid, or one of its dependencies was missing.
- clean_extra_data()[source]¶
Clean the extra_data field.
This will ensure that the field is always a dictionary.
- Returns:
The extra_data dictionary.
- Return type:
- Raises:
django.core.exceptions.ValidationError – The value was not a dictionary.
- is_valid()[source]¶
Return whether or not the form is valid.
This will return True if the form fields are all valid, if there’s no certificate error, host key error, and if the form isn’t being re-displayed after canceling an SSH key or HTTPS certificate verification.
This also takes into account the validity of any relevant subforms.
- Returns:
True
if the form is valid.False
if it is not.- Return type:
- save(commit=True)[source]¶
Save the repository.
This will save some of the general information for the repository and the hosting service (if selected), and use the subforms to save the rest.
This must be called after
is_valid()
.- Parameters:
commit (
bool
, optional) –Whether to save the repository to the database.
If
False
, the repository will be constructed but not saved. It is then the responsibility of the caller to callRepository.save()
andsave_m2m()
.- Returns:
The resulting repository.
- Return type:
- Raises:
ValueError – The form had pending errors, and could not be saved.
- class Meta[source]¶
Bases:
object
- model[source]¶
alias of
Repository
- __annotations__ = {'cert': 'Optional[LegacyCertificate]', 'certerror': 'Optional[Union[CertificateVerificationError, LegacyUnverifiedCertificateError]]'}¶
- declared_fields = {'associate_ssh_key': <django.forms.fields.BooleanField object>, 'bug_tracker': <django.forms.fields.CharField object>, 'bug_tracker_hosting_account_username': <django.forms.fields.CharField object>, 'bug_tracker_hosting_url': <django.forms.fields.CharField object>, 'bug_tracker_plan': <django.forms.fields.ChoiceField object>, 'bug_tracker_type': <django.forms.fields.ChoiceField object>, 'bug_tracker_use_hosting': <django.forms.fields.BooleanField object>, 'force_authorize': <django.forms.fields.BooleanField object>, 'hosting_account': <django.forms.models.ModelChoiceField object>, 'hosting_type': <django.forms.fields.ChoiceField object>, 'reedit_repository': <django.forms.fields.BooleanField object>, 'repository_plan': <django.forms.fields.ChoiceField object>, 'review_groups': <django.forms.models.ModelMultipleChoiceField object>, 'tool': <django.forms.fields.ChoiceField object>, 'trust_host': <django.forms.fields.BooleanField object>, 'users': <django.forms.models.ModelMultipleChoiceField object>}¶