Jump to >

reviewboard.scmtools.forms

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

Bases: django.forms.widgets.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.

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]

Bases: django.forms.forms.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 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
__init__(*args, **kwargs)[source]

Initialize the form.

Subclasses should use this to alter the fields shown in the form, if needed.

Parameters:
  • *args (tuple) – Additional positional arguments for the parent form.
  • **kwargs (dict) – Additional keyword arguments for the parent form.
Keyword Arguments:
 
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]

Bases: reviewboard.scmtools.forms.BaseRepositorySubForm

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]

Bases: reviewboard.scmtools.forms.BaseRepositorySubForm

Base class for any repository information forms.

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

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.

scmtool_cls

The SCMTool subclass used for this form.

Type:type
__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.

Parameters:**kwargs (dict) – Additional keyword arguments for the parent form.
Keyword Arguments:
 scmtool_cls (type) – The subclass of SCMTool that this form represents.
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.

__repr__()[source]

Return a string representation of the form.

Parameters:
  • unicode
  • string representation. (The) –
class BaseSCMToolAuthForm(**kwargs)[source]

Bases: reviewboard.scmtools.forms.SCMToolSubFormMixin, reviewboard.scmtools.forms.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 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]

Bases: reviewboard.scmtools.forms.SCMToolSubFormMixin, reviewboard.scmtools.forms.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, 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]

Bases: reviewboard.scmtools.forms.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: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]

Bases: reviewboard.scmtools.forms.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 <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.

__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: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(*args, **kwargs)[source]

Bases: reviewboard.site.mixins.LocalSiteAwareModelFormMixin, django.forms.models.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.

REPOSITORY_HOSTING_FIELDSET = _(u'Repository Hosting')[source]
REPOSITORY_INFO_FIELDSET = _(u'Repository Information')[source]
BUG_TRACKER_FIELDSET = _(u'Bug Tracker')[source]
SSH_KEY_FIELDSET = _(u'Review Board Server SSH Key')[source]
NO_HOSTING_SERVICE_ID = u'custom'[source]
NO_HOSTING_SERVICE_NAME = _(u'(None - Custom Repository)')[source]
NO_BUG_TRACKER_ID = u'none'[source]
NO_BUG_TRACKER_NAME = _(u'(None)')[source]
CUSTOM_BUG_TRACKER_ID = u'custom'[source]
CUSTOM_BUG_TRACKER_NAME = _(u'(Custom Bug Tracker)')[source]
IGNORED_SERVICE_IDS = (u'none', u'custom')[source]
DEFAULT_PLAN_ID = u'default'[source]
DEFAULT_PLAN_NAME = _(u'Default')[source]
NO_KEY_HELP_FMT = _(u'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__(*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.

Parameters:
  • *args (tuple) – Positional arguments to pass to the parent class.
  • **kwargs (dict) – Keyword arguments to pass to the parent class.
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]
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_base_url()[source]
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.
class Meta[source]
model[source]

alias of reviewboard.scmtools.models.Repository

widgets = {u'bug_tracker': <django.forms.widgets.TextInput object>, u'name': <django.forms.widgets.TextInput object>, u'review_groups': <django.contrib.admin.widgets.FilteredSelectMultiple object>}[source]
fields = u'__all__'[source]
exclude = (u'username', u'password', u'path', u'mirror_path', u'raw_file_url', u'tool')[source]
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>, 'tool': <django.forms.fields.ChoiceField object>, 'trust_host': <django.forms.fields.BooleanField object>, 'users': <django.forms.models.ModelMultipleChoiceField object>}[source]