Jump to >

reviewboard.scmtools.forms

class HostingAccountWidget(attrs=None, choices=())[source]

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.

render(*args, **kwargs)[source]

Render the widget.

Parameters
  • *args (tuple) – Arguments for the render.

  • **kwargs (dict) – Keyword arguments for the render.

Returns

The HTML for the widget.

Return type

django.utils.safestring.SafeText

class BaseRepositorySubForm(*args, **kwargs)[source]

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 or HostingService). 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 define Meta.help_texts and Meta.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.

Type

reviewboard.site.models.LocalSite

repository

The repository being configured. This is allowed to be None, mainly for testing purposes, but will always have a value when constructed by RepositoryForm.

Type

reviewboard.scmtools.models.Repository

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

dict

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.

save()[source]

Save information from the form.

Subclasses must override this.

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’s load() or get_initial_data().

Parameters
  • obj (django.db.models.Model) – The model object to load data from. This is expected to have an extra_data field.

  • field_names (list of unicode, 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 of unicode, optional) – Names of fields that should be loaded directly from attributes on obj, instead of the object’s extra_data.

  • norm_key_func (callable, optional) – A function that normalizes a key before looking up in the object’s extra_data. If not provided, this defaults to add_prefix().

Returns

The loaded field data.

Return type

dict

class BaseRepositoryAuthSubForm(*args, **kwargs)[source]

Base class for any repository authentication forms.

Third-parties will never need to subclass this directly. Instead, subclass one of:

class BaseRepositoryInfoSubForm(*args, **kwargs)[source]

Base class for any repository information forms.

Third-parties will never need to subclass this directly. Instead, subclass one of:

class SCMToolSubFormMixin(**kwargs)[source]

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.

scmtool_cls

The SCMTool subclass used for this form.

Type

type

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

dict

save()[source]

Save information to the repository.

This will store the content of the fields in the repository.

Subclasses will generally not need to override this.

class BaseSCMToolAuthForm(**kwargs)[source]

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 or password will be set directly on the equivalent Repository model fields. Any other fields will be stored in Repository.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.

class BaseSCMToolRepositoryForm(**kwargs)[source]

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, or raw_file_url will be set directly on the equivalent Repository model fields. Any other fields will be stored in Repository.extra_data, using a key in the form of <scmtoolid>_<fieldname>. The exception is the field use_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.

class StandardSCMToolAuthForm(**kwargs)[source]

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

unicode

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

unicode

class StandardSCMToolRepositoryForm(**kwargs)[source]

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 <if SCMTool.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.

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

unicode

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

unicode

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

unicode

class RepositoryForm(data=None, *args, **kwargs)[source]

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.

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
  • bound_only (bool, optional) – Whether to limit results to bound subforms (those that have been populated with data from a form submission).

  • with_auth_forms (bool, optional) – Whether to include authentication forms in the results.

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

bool

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

dict

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

unicode

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

reviewboard.scmtools.models.Tool

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

dict

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

bool

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 call Repository.save() and save_m2m().

Returns

The resulting repository.

Return type

reviewboard.scmtools.models.Repository

Raises

ValueError – The form had pending errors, and could not be saved.