reviewboard.extensions.hooks¶
-
class
AuthBackendHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.BaseRegistryHook
A hook for registering an authentication backend.
Authentication backends control user authentication, registration, user lookup, and user data manipulation.
This hook takes the class of an authentication backend that should be made available to the server.
-
initialize
(backend_cls)[source]¶ Initialize the hook.
This will register the provided authentication backend.
Parameters: backend_cls (type) – The authentication backend to register. This should be a subclass of AuthBackend
.
-
-
class
AvatarServiceHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.BaseRegistryHook
“A hook for adding avatar services.
This hook will register services with the avatar services registry and unregister them when the hook is shut down.
-
initialize
(service)[source]¶ Initialize the avatar service hook with the given service.
Parameters: service (type) – The avatar service class to register.
This must be a subclass of
djblets.avatars.services.base.AvatarService
.
-
-
class
AccountPagesHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.BaseRegistryMultiItemHook
A hook for adding new pages to the My Account page.
A page can contain one or more forms or even a custom template allowing for configuration of an extension.
This takes a list of AccountPage classes as parameters, which it will later instantiate as necessary. Each page can be pre-populated with one or more custom AccountPageForm classes.
-
initialize
(page_classes)[source]¶ Initialize the hook.
This will register each of the provided account page classes.
Parameters: page_classes (list of type) – The list of page classes to register. Each must be a subclass of AccountPage
.
-
-
class
AccountPageFormsHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for adding new forms to a page in the My Account page.
This is used to add custom forms to a page in the My Account page. The form can be used to provide user-level customization of an extension, through a traditional form-based approach or even through custom JavaScript.
This hook takes the ID of a registered page where the form should be placed. Review Board supplies the following built-in page IDs:
settings
authentication
profile
groups
Any registered page ID can be provided, whether from this extension or another.
Form classes can only be added to a single page.
-
initialize
(page_id, form_classes)[source]¶ Initialize the hook.
This will register each of the provided page form classes on the account page matching the provided ID.
Parameters: - page_id (unicode) – The page ID corresponding to a registered
AccountPage
. - form_classes (list of type) – The list of form classes to register on the page. Each class
must be a subclass of
AccountPageForm
.
- page_id (unicode) – The page ID corresponding to a registered
-
class
AdminWidgetHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.BaseRegistryHook
A hook for adding a new widget to the administration dashboard.
- Version Changed::
4.0: Widget classes should now subclass
AdminBaseWidget
instead ofWidget
. Note that this will require a full rewrite of the widget.The
primary
argument is no longer supported when instantiating the hook, and will be ignored. Callers should remove it.Support for legacy widgets and arguments will be removed in Review Board 5.0.
-
class
DataGridSidebarItemsHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for adding items to the sidebar of a datagrid.
Extensions can use this hook to plug new items into the sidebar of any datagrid supporting sidebars.
The items can be any subclass of
reviewboard.datagrids.sidebar.BaseSidebarItem
, including the built-inreviewboard.datagrids.sidebar.BaseSidebarSection
and built-inreviewboard.datagrids.sidebar.SidebarNavItem
.-
initialize
(datagrid, item_classes)[source]¶ Initialize the hook.
This will register the provided datagrid sidebar item classes in the provided datagrid.
Parameters: - datagrid (type) – The datagrid class to register the items on. The datagrid must have a sidebar, or an error will occur.
- item_classes (list of type) – The list of item classes to register on the datagrid’s
sidebar. Each must be a subclass of
BaseSidebarItem
.
Raises: ValueError
– A datagrid was provided that does not contain a sidebar.
-
-
class
DashboardColumnsHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.DataGridColumnsHook
A hook for adding custom columns to the dashboard.
Extensions can use this hook to provide one or more custom columns in the dashboard. These columns can be added by users, moved around, and even sorted, like other columns.
Each value passed to
columns
must be an instance ofdjblets.datagrid.grids.Column
.It also must have an
id
attribute set. This must be unique within the dashboard. It is recommended to use a vendor-specific prefix to the ID, in order to avoid conflicts.
-
class
DashboardSidebarItemsHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.DataGridSidebarItemsHook
A hook for adding items to the sidebar of the dashboard.
Extensions can use this hook to plug new items into the sidebar of the dashboard. These will appear below the built-in items.
The items can be any subclass of
reviewboard.datagrids.sidebar.BaseSidebarItem
, including the built-inreviewboard.datagrids.sidebar.BaseSidebarSection
and built-inreviewboard.datagrids.sidebar.SidebarNavItem
.-
initialize
(item_classes)[source]¶ Initialize the hook.
This will register the provided datagrid sidebar item classes in the Dashboard.
Parameters: item_classes (list of type) – The list of item classes to register on the datagrid’s sidebar. Each must be a subclass of BaseSidebarItem
.
-
-
class
HostingServiceHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for registering a hosting service.
-
initialize
(service_cls)[source]¶ Initialize the hook.
This will register the hosting service.
Parameters: service_cls (type) – The hosting service class to register. This must be a subclass of HostingService
.Raises: ValueError
– The service’shosting_service_id
attribute was not set.
-
-
class
IntegrationHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.integrations.base.GetIntegrationManagerMixin
,djblets.integrations.hooks.BaseIntegrationHook
A hook for registering new integration classes.
Integrations enable Review Board to connect with third-party services in specialized ways. This class makes it easy to register new integrations on an extension, binding their lifecycles to that of the extension.
Bases:
djblets.extensions.hooks.ExtensionHook
A hook for adding entries to the main navigation bar.
This takes a list of entries. Each entry represents something on the navigation bar, and is a dictionary with the following keys:
label
:- The label to display
url
:- The URL to point to.
url_name
:- The name of the URL to point to.
Only one of
url
orurl_name
is required.url_name
will take precedence.Optionally, a callable can be passed in for
is_enabled_for
, which takes a single argument (the user) and returns True or False, indicating whether the entries should be shown. If this is not passed in, the entries are always shown (including for anonymous users).If your hook needs to access the template context, it can override
get_entries()
and return results from there.Initialize the hook.
This will register each of the entries in the navigation bar.
Parameters: - entries (list of dict) – The list of dictionary entries representing navigation bar items, as documented above.
- is_enabled_for (callable, optional) –
The optional function used to determine if these entries should appear for a given page. This is in the format of:
def is_enabled_for(user, request, local_site_name, **kwargs): return True
If not provided, the entries will be visible on every page.
- *args (tuple) – Additional positional arguments. Subclasses should always pass these to this class.
- **kwargs (dict) – Additional keyword arguments. Subclasses should always pass these to this class.
Return the navigation bar entries defined in this hook.
This can be overridden by subclasses if they need more control over the entries or need to access the template context.
Parameters: context (django.template.RequestContext) – The template context for the page. Returns: The list of navigation bar entries. This will be empty if the entries are not enabled for this page. Return type: list of dict
-
class
ReviewRequestApprovalHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for determining if a review request is approved.
Extensions can use this to hook into the process for determining review request approval, which may impact any scripts integrating with Review Board to, for example, allow committing to a repository.
-
is_approved
(review_request, prev_approved, prev_failure)[source]¶ Determine if the review request is approved.
This function is provided with the review request and the previously calculated approved state (either from a prior hook, or from the base state of
ship_it_count > 0 and issue_open_count == 0
).If approved, this should return True. If unapproved, it should return a tuple with False and a string briefly explaining why it’s not approved. This may be displayed to the user.
It generally should also take the previous approved state into consideration in this choice (such as returning False if the previous state is False). This is, however, fully up to the hook.
The approval decision may be overridden by any following hooks.
Parameters: - review_request (reviewboard.reviews.models.review_request.ReviewRequest) – The review request being checked for approval.
- prev_approved (bool) – The previously-calculated approval result, either from another hook or by Review Board.
- prev_failure (unicode) – The previously-calculated approval failure message, either from another hook or by Review Board.
Returns: Either a boolean indicating approval (re-using
prev_failure
, if not approved), or a tuple in the form of(approved, failure_message)
.Return type:
-
-
class
ReviewRequestFieldSetsHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for creating fieldsets on the side of the review request page.
A fieldset contains one or more fields, and is mainly used to separate groups of fields from each other.
This takes a list of fieldset classes as parameters, which it will later instantiate as necessary. Each fieldset can be pre-populated with one or more custom field classes.
-
initialize
(fieldsets)[source]¶ Initialize the hook.
This will register each of the provided fieldsets for review requests.
Parameters: fieldsets (list of type) – The list of fieldset classes to register. Each must be a subclass of BaseReviewRequestFieldSet
.Raises: djblets.registries.errors.ItemLookupError
– A fieldset was already registered matching an ID from this list.
-
-
class
ReviewRequestFieldsHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for creating fields on the review request page.
This is used to create custom fields on a review request page for requesting and storing data. A field can be editable, or it can be only for display purposes. See the classes in
reviewboard.reviews.fields
for more information and documentation.This hook takes the ID of a registered fieldset where the provided field classes should be added. Review Board supplies three built-in fieldset IDs:
main
:- The fieldset with Description and Testing Done.
info
:- The “Information” fieldset on the side.
reviewers
:- The “Reviewers” fieldset on the side.
Any registered fieldset ID can be provided, whether from this extension or another.
Field classes can only be added to a single fieldset.
-
initialize
(fieldset_id, fields)[source]¶ Initialize the hook.
This will register each of the provided field classes into the fieldset with the given ID.
Parameters: - fieldset_id (unicode) – The ID of the
BaseReviewRequestFieldSet
to register. - fields (list of type) – The list of fields to register into the fieldset. Each must be
a subclass of
BaseReviewRequestField
.
- fieldset_id (unicode) – The ID of the
-
class
WebAPICapabilitiesHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
This hook allows adding capabilities to the web API server info.
Note that this does not add the functionality, but adds to the server info listing.
Extensions may only provide one instance of this hook. All capabilities must be registered at once.
-
initialize
(caps)[source]¶ Initialize the hook.
This will register each of the capabilities for the API.
Parameters: caps (dict) – The dictionary of capabilities to register. Each key msut be a string, and each value should be a boolean or a dictionary of string keys to booleans. Raises: KeyError
– Capabilities have already been registered by this extension.
-
-
class
CommentDetailDisplayHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
This hook allows adding details to the display of comments.
The hook can provide additional details to display for a comment in a review and e-mails.
-
render_review_comment_detail
(comment)[source]¶ Render additional HTML for a comment on the page.
Subclasses must implement this to provide HTML for use on the review request page or review dialog.
The result is assumed to be HTML-safe. It’s important that subclasses escape any data as needed.
Parameters: comment (reviewboard.reviews.models.base_comment.BaseComment) – The comment to render HTML for, Returns: The resulting HTML for the comment. This can be an empty string. Return type: django.utils.safestring.SafeText
-
render_email_comment_detail
(comment, is_html)[source]¶ Render additional text or HTML for a comment in an e-mail.
Subclasses must implement this to provide text or HTML (depending on the
is_html
flag) for use in an e-mail.If rendering HTML, the result is assumed to be HTML-safe. It’s important that subclasses escape any data as needed.
Parameters: - comment (reviewboard.reviews.models.base_comment.BaseComment) – The comment to render HTML for,
- is_html (bool) – Whether this must return HTML content.
Returns: The resulting HTML for the comment. This can be an empty string.
Return type:
-
-
class
ReviewUIHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
This hook allows integration of Extension-defined Review UIs.
This accepts a list of Review UIs specified by the Extension and registers them when the hook is created. Likewise, it unregisters the same list of Review UIs when the Extension is disabled.
-
initialize
(review_uis)[source]¶ Initialize the hook.
This will register the list of review UIs for use in reviewing file attachments.
Parameters: review_uis (list of type) – The list of review UI classes to register. Each must be a subclass of FileAttachmentReviewUI
.Raises: TypeError
– The provided review UI class is not of a compatible type.
-
-
class
FileAttachmentThumbnailHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
This hook allows custom thumbnails to be defined for file attachments.
This accepts a list of mimetype handlers specified by the Extension that must:
- Subclass
reviewboard.attachments.mimetypes.MimetypeHandler
- Define a list of file mimetypes it can handle in a class variable
called
supported_mimetypes
- Define how to generate a thumbnail of that mimetype by overriding
the instance function
def get_thumbnail(self):
These mimetype handlers are registered when the hook is created. Likewise, it unregisters the same list of mimetype handlers when the extension is disabled.
-
initialize
(mimetype_handlers)[source]¶ Initialize the hook.
This will register each of the provided mimetype handler classes.
Parameters: mimetype_handlers (list of type) – The list of mimetype handlers to register. Each must be a subclass of MimetypeHandler
.Raises: TypeError
– One or more of the provided classes are not of the correct type.
- Subclass
-
class
ActionHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for injecting clickable actions into the UI.
Actions are displayed either on the action bar of each review request or in the page header.
The provided
actions
parameter must be a list of actions. Each action may be adict
with the following keys:id
(optional):- The ID of the action.
label
:- The label for the action.
url
:The URL to invoke when the action is clicked.
If we want to invoke a JavaScript action, then this should be
#
, and there should be a selector on theid
field to attach the handler (as opposed to ajavascript:
URL, which doesn’t work on all browsers).image
(optional):- The path to the image used for the icon.
image_width
(optional):- The width of the image.
image_height
(optional):- The height of the image.
If our hook needs to access the template context, then it can override
get_actions()
and return results from there.-
initialize
(actions=None, *args, **kwargs)[source]¶ Initialize this action hook.
Parameters: - actions (list, optional) – The list of actions (of type
dict
orBaseReviewRequestAction
) to be added. - *args (tuple) – Extra positional arguments.
- **kwargs (dict) – Extra keyword arguments.
- actions (list, optional) – The list of actions (of type
-
get_actions
(context)[source]¶ Return the list of action information for this action hook.
Parameters: context (django.template.Context) – The collection of key-value pairs available in the template. Returns: The list of action information for this action hook. Return type: list
-
class
BaseReviewRequestActionHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.AppliesToURLMixin
,reviewboard.extensions.hooks.ActionHook
A base hook for adding review request actions to the action bar.
Review request actions are displayed on the action bar (alongside default actions such as Download Diff and Ship It!) of each review request. This action bar is displayed on three main types of pages:
- Review Request Pages:
- Where reviews are displayed.
- File Attachment Pages:
- Where files like screenshots can be reviewed.
- Diff Viewer Pages:
- Where diffs/interdiffs can be viewed side-by-side.
Each action should be an instance of
BaseReviewRequestAction
(in particular, each action could be an instance of the subclassBaseReviewRequestMenuAction
). For backwards compatibility, actions may also be supplied asActionHook
-style dictionaries.-
initialize
(actions=None, apply_to=None, *args, **kwargs)[source]¶ Initialize this action hook.
Parameters: - actions (list, optional) – The list of actions (of type
dict
orBaseReviewRequestAction
) to be added. - apply_to (list of unicode, optional) – The list of URL names that this action hook will apply to.
- *args (tuple) – Extra positional arguments.
- **kwargs (dict) – Extra keyword arguments.
Raises: KeyError
– Some dictionary is not anActionHook
-style dictionary.ValueError
– Some review request action is neither aBaseReviewRequestAction
nor adict
instance.
- actions (list, optional) – The list of actions (of type
-
convert_action
(action_dict)[source]¶ Convert the given dictionary to a review request action instance.
Parameters: action_dict (dict) – A dictionary representing a review request action, as specified by the ActionHook
class.Returns: The corresponding review request action instance. Return type: BaseReviewRequestAction Raises: KeyError
– The given dictionary is not anActionHook
-style dictionary.
-
class
ReviewRequestActionHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.BaseReviewRequestActionHook
A hook for adding review request actions to review request pages.
By default, actions that are passed into this hook will only be displayed on review request pages and not on any file attachment pages or diff viewer pages.
-
initialize
(actions=None, apply_to=None)[source]¶ Initialize this action hook.
Parameters: - actions (list, optional) – The list of actions (of type
dict
orBaseReviewRequestAction
) to be added. - apply_to (list of unicode, optional) – The list of URL names that this action hook will apply to. By default, this will apply to the main review request page only.
Raises: KeyError
– Some dictionary is not anActionHook
-style dictionary.ValueError
– Some review request action is neither aBaseReviewRequestAction
nor adict
instance.
- actions (list, optional) – The list of actions (of type
-
-
class
ReviewRequestDropdownActionHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ReviewRequestActionHook
A hook for adding dropdown menu actions to review request pages.
Each menu action should be an instance of
BaseReviewRequestMenuAction
. For backwards compatibility, menu actions may also be supplied as dictionaries with the following keys:id
(optional):- The ID of the action.
label
:- The label for the dropdown menu action.
items
:- A list of
ActionHook
-style dictionaries.
Example
actions = [{ 'id': 'sample-menu-action', 'label': 'Sample Menu', 'items': [ { 'id': 'first-item-action', 'label': 'Item 1', 'url': '#', }, { 'label': 'Item 2', 'url': '#', }, ], }]
-
convert_action
(action_dict)[source]¶ Convert the given dictionary to a review request action instance.
Children action dictionaries are recursively converted to action instances.
Parameters: action_dict (dict) – A dictionary representing a review request menu action, as specified by the ReviewRequestDropdownActionHook
class.Returns: The corresponding review request menu action instance. Return type: BaseReviewRequestMenuAction Raises: KeyError
– The given review request menu action dictionary is not aReviewRequestDropdownActionHook
-style dictionary.
-
class
DiffViewerActionHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.BaseReviewRequestActionHook
A hook for adding review request actions to diff viewer pages.
By default, actions that are passed into this hook will only be displayed on diff viewer pages and not on any review request pages or file attachment pages.
-
initialize
(actions=None, apply_to=[u'view-diff', u'view-interdiff', u'view-diff-revision'])[source]¶ Initialize this action hook.
Parameters: - actions (list, optional) – The list of actions (of type
dict
orBaseReviewRequestAction
) to be added. - apply_to (list of unicode, optional) – The list of URL names that this action hook will apply to.
Raises: KeyError
– Some dictionary is not anActionHook
-style dictionary.ValueError
– Some review request action is neither aBaseReviewRequestAction
nor adict
instance.
- actions (list, optional) – The list of actions (of type
-
-
class
HeaderActionHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ActionHook
A hook for adding actions to the page header.
-
class
HeaderDropdownActionHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ActionHook
A hook for adding dropdown menu actions to the page header.
-
class
UserInfoboxHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for adding information to the user infobox.
Extensions can use this hook to add additional pieces of data to the box which pops up when hovering the mouse over a user.
-
initialize
(template_name=None)[source]¶ Initialize the hook.
Parameters: template_name (six.text_type) – The template to render with the default render()
method.
-
get_extra_context
(user, request, local_site, **kwargs)[source]¶ Return extra context to use when rendering the template.
This may be overridden in order to make use of the default
render()
method.Parameters: - user (django.contrib.auth.models.User) – The user whose infobox is being shown.
- request (django.http.HttpRequest) – The request for the infobox view.
- local_site (reviewboard.site.models.LocalSite) – The local site, if any.
- **kwargs (dict) – Additional keyword arguments.
Returns: Additional context to include when rendering the template.
Return type:
-
get_etag_data
(user, request, local_site, **kwargs)[source]¶ Return data to be included in the user infobox ETag.
The infobox view uses an ETag to enable browser caching of the content. If the extension returns data which can change, this method should return a string which is unique to that data.
Parameters: - user (django.contrib.auth.models.User) – The user whose infobox is being shown.
- request (django.http.HttpRequest) – The request for the infobox view.
- local_site (reviewboard.site.models.LocalSite) – The local site, if any.
- **kwargs (dict) – Additional keyword arguments.
Returns: A string to be included in the ETag for the view.
Return type: unicode
-
render
(user, request, local_site, **kwargs)[source]¶ Return content to include in the user infobox.
This may be overridden in the case where providing a custom template and overriding
get_extra_context()
is insufficient.Parameters: - user (django.contrib.auth.models.User) – The user whose infobox is being shown.
- request (django.http.HttpRequest) – The request for the infobox view.
- local_site (reviewboard.site.models.LocalSite) – The local site, if any.
- **kwargs (dict) – Additional keyword arguments.
Returns: Text to include in the infobox HTML.
Return type:
-
-
class
UserPageSidebarItemsHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.DataGridSidebarItemsHook
A hook for adding items to the sidebar of the user page.
Extensions can use this hook to plug new items into the sidebar of the user page. These will appear below the built-in items.
The items can be any subclass of
reviewboard.datagrids.sidebar.BaseSidebarItem
, including the built-inreviewboard.datagrids.sidebar.BaseSidebarSection
and built-inreviewboard.datagrids.sidebar.SidebarNavItem
.-
initialize
(item_classes)[source]¶ Initialize the hook.
This will register the provided datagrid sidebar item classes in the user page’s datagrid.
Parameters: item_classes (list of type) – The list of item classes to register on the datagrid’s sidebar. Each must be a subclass of BaseSidebarItem
.
-
-
class
EmailHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for changing the recipients of e-mails.
Extensions can use this hook to change the contents of the To and CC fields of e-mails. This should be subclassed in an extension to provide the desired behaviour. This class is a base class for more specialized extension hooks. If modifying only one type of e-mail’s fields is desired, one of the following classes should be subclassed instead.
ReviewPublishedEmailHook
ReviewReplyPublishedEmailHook
ReviewRequestPublishedEmailHook
ReviewRequestClosedEmailHook
However, if more specialized behaviour is desired, this class can be subclassed.
-
initialize
(signals)[source]¶ Initialize the hook.
Parameters: signals (list) – A list of
Signals
that, when triggered, will cause e-mails to be sent. Valid signals are:
-
get_to_field
(to_field, **kwargs)[source]¶ Return the To field for the e-mail.
Parameters: Returns: The desired To field.
Return type:
-
class
ReviewPublishedEmailHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review publishing e-mails.
This hook must be subclassed. The caller is expected to override
get_to_field()
and/orget_cc_field()
.-
get_to_field
(to_field, review, user, review_request, to_owner_only, **kwargs)[source]¶ Return the To field for the e-mail.
Parameters: - to_field (set) – A set of
Users
andGroups
that will receive the e-mail. - review (reviewboard.reviews.models.Review) – The review that was published.
- user (django.contrib.auth.models.User) – The user who published the review.
- review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was reviewed.
- to_owner_only (bool) – Whether or not the review was marked as being targeted at only the submitter.
- **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, review, user, review_request, to_owner_only, **kwargs)[source]¶ Return the CC field for the e-mail.
Parameters: - cc_field (set) – A set of
Users
andGroups
that will receive a carbon copy of the e-mail. - review (reviewboard.reviews.models.Review) – The review that was published.
- user (django.contrib.auth.models.User) – The user who published the review.
- review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was reviewed.
- to_owner_only (bool) – Whether or not the review was marked as being targeted at only the submitter.
- **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired CC field.
Return type: - cc_field (set) – A set of
-
-
class
ReviewReplyPublishedEmailHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review reply publishing e-mails.
This hook must be subclassed. The caller is expected to override
get_to_field()
and/orget_cc_field()
.-
get_to_field
(to_field, reply, user, review_request, **kwargs)[source]¶ Return the To field for the e-mail.
Parameters: - to_field (set) – A set of
Users
andGroups
that will receive the e-mail. - reply (reviewboard.reviews.models.Review) – The review reply that was published.
- user (django.contrib.auth.models.User) – The user who published the review reply.
- review (reviewboard.reviews.model.Review) – The review the reply is in reply to.
- review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was reviewed.
- **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, reply, user, review_request, **kwargs)[source]¶ Return the CC field for the e-mail.
Parameters: - to_field (set) – A set of
Users
andGroups
that will receive a carbon copy of the e-mail - reply (reviewboard.reviews.models.Review) – The review reply that was published.
- user (django.contrib.auth.models.User) – The user who published the reply.
- review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was reviewed.
- **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired CC field.
Return type: - to_field (set) – A set of
-
-
class
ReviewRequestClosedEmailHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review request closing e-mails.
This hook must be subclassed. The caller is expected to override
get_to_field()
and/orget_cc_field()
.-
get_to_field
(to_field, review_request, user, close_type, **kwargs)[source]¶ Return the To field for the e-mail.
Parameters: - to_field (set) – A set of
Users
andGroups
that will receive the e-mail. - review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was published.
- user (django.contrib.auth.models.User) – The user who closed the review request.
- close_type (unicode) – How the review request was closed. This is one of
SUBMITTED
orDISCARDED
. - **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, review_request, user, close_type, **kwargs)[source]¶ Return the CC field for the e-mail.
Parameters: - to_field (set) – A set of
Users
andGroups
that will receive a carbon copy of the e-mail. - review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was published.
- user (django.contrib.auth.models.User) – The user who closed the review request.
- close_type (unicode) – How the review request was closed. This is one of
SUBMITTED
orDISCARDED
. - **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired CC field.
Return type: - to_field (set) – A set of
-
-
class
ReviewRequestPublishedEmailHook
(extension, *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review request publishing e-mails.
This hook must be subclassed. The caller is expected to override
get_to_field()
and/orget_cc_field()
.-
get_to_field
(to_field, review_request, user, **kwargs)[source]¶ Return the To field for the e-mail.
Parameters: - to_field (set) – A set of
Users
andGroups
that will receive the e-mail. - review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was published.
- user (django.contrib.auth.models.User) – The user who published the review request.
- **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, review_request, user, **kwargs)[source]¶ Return the CC field for the e-mail.
Parameters: - to_field (set) – A set of
Users
andGroups
that will receive a carbon copy of the e-mail. - review_request (reviewboard.reviews.models.ReviewRequest) – The review request that was published.
- user (django.contrib.auth.models.User) – The user who published the review request.
- **kwargs (dict) – Additional keyword arguments, since the signature may change in the future.
Returns: The desired CC field.
Return type: - to_field (set) – A set of
-
-
class
APIExtraDataAccessHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for setting access states to extra data fields.
Extensions can use this hook to register
extra_data
fields with certain access states on subclasses ofWebAPIResource
.This accepts a list of
field_set
values specified by the Extension and registers them when the hook is created. Likewise, it unregisters the same list offield_set
values when the Extension is disabled.Each element of
field_set
is a 2-tuple
where the first element of the tuple is the field’s path (as atuple
) and the second is the field’s access state (as one ofACCESS_STATE_PUBLIC
orACCESS_STATE_PRIVATE
).Example
obj.extra_data = { 'foo': { 'bar' : 'private_data', 'baz' : 'public_data' } } ... APIExtraDataAccessHook( extension, resource, [ (('foo', 'bar'), ExtraDataAccessLevel.ACCESS_STATE_PRIVATE, ])
-
initialize
(resource, field_set)[source]¶ Initialize the APIExtraDataAccessHook.
Parameters: - resource (reviewboard.webapi.base.WebAPIResource) – The resource to modify access states for.
- field_set (list) – Each element of
field_set
is a 2-tuple
where the first element of the tuple is the field’s path (as atuple
) and the second is the field’s access state (as one ofACCESS_STATE_PUBLIC
orACCESS_STATE_PRIVATE
).
-
-
class
FileDiffACLHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for checking ACLs on diff files.
Extensions can use this hook to connect repository ACLs into the Review Board access system. This is provided as an extension hook because systems may be deployed in various ways, and SCM usernames may not necessarily match Review Board usernames.
New in version 4.0.5: This is experimental in 4.0.x, with plans to make it stable for 5.0. The API may change during this time.
-
is_accessible
(diffset, user, **kwargs)[source]¶ Return whether the given file is accessible by the given user.
Parameters: - diffset (reviewboard.diffviewer.models.DiffSet) – The diffset containing the file.
- user (django.contrib.auth.models.User) – The user to check.
- **kwargs (dict, unused) – Additional keyword arguments for future expansion.
Returns: False if the user does not have access to the file. True if the user explicitly does have access. None if the extension did not check for this diffset or repository (so that other hook points can continue).
Return type:
-
-
class
ConsentRequirementHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.BaseRegistryHook
Registers a ConsentRequirement for use of personal data.
-
class
DataGridColumnsHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
Adds columns to a datagrid.
This hook allows an extension to register new columns to any datagrid. These columns can be added by the user, rearranged, and sorted, like any other column.
Each column must have an id already set, and it must be unique.
-
class
ExtensionHook
(extension, *args, **kwargs)[source]¶ Bases:
object
The base class for a hook into some part of an application.
ExtensionHooks are classes that can hook into an
ExtensionHookPoint
to provide some level of functionality in an application. A consuming application should provide a subclass of ExtensionHook that will provide functions for getting data or anything else that’s needed. Extensions may then subclass or initialize that specific ExtensionHook.A base ExtensionHook subclass must use
ExtensionHookPoint
as a metaclass. All hooks deriving from that subclass will be registered along with that hook point.Example
from django.utils import six from myproject.nav import register_thing, unregister_thing_id @six.add_metaclass(ExtensionHookPoint) class ThingHook(ExtensionHook): def initialize(self, thing_id): self.thing_id = thing_id register_thing(self.thing_id) def shutdown(self): unregister_thing(self.thing_id)
Changed in version 1.0: Starting with Djblets 1.0, extension hooks should implement the
initialize()
method to handle any initialization. It no longer needs to call the parentshutdown()
method, either. However, to retain compatibility with older versions, they may still override__init__()
and may call the parentshutdown()
. See those methods for more details.-
extension
¶ The parent extension, or another object that can act as a hook owner.
Type: djblets.extensions.extension.Extension
-
hook_state
¶ The state of the hook. This will be one of
HOOK_STATE_DISABLED
,HOOK_STATE_ENABLED
,HOOK_STATE_DISABLING
, orHOOK_STATE_ENABLING
.Type: int
-
__init__
(extension, *args, **kwargs)[source]¶ Initialize the ExtensionHook.
This is called when creating an instance of the hook. This will call
enable_hook()
with the provided arguments, beginning the internal initialization process. That will then callinitialize()
, which is responsible for any initialization of state in the subclass.Subclasses should override
initialize()
in order to provide any state initialization, rather than overriding this method.Changed in version 1.0: Prior to Djblets 1.0, initialization all happened in
__init__()
. Code that needs to remain compatible with older versions should continue to do so, but otherwise this code should move toinitialize()
.Parameters: - extension (djblets.extensions.extension.Extension) – The parent extension, or another object that can act as a hook owner.
- start_enabled (bool, optional) – Whether to enable the hook once constructed. This defaults
to
True
.
-
initialize
(*args, **kwargs)[source]¶ Initialize the extension hook’s state.
Extension subclasses can perform any custom initialization they need here.
Any additional arguments passed to the hook during construction will be passed to this as well.
While in this function,
hook_state
will be set toHOOK_STATE_ENABLING
.By default, this does nothing.
New in version 1.0.
Parameters: Example
@six.add_metaclass(ExtensionHookPoint) class ThingHook(ExtensionHook): def initialize(self, thing_id): self.thing_id = thing_id register_thing(self.thing_id)
-
shutdown
()[source]¶ Shut down the extension.
Extension subclasses can perform any custom cleanup they need here.
While in this function,
hook_state
will be set toHOOK_STATE_DISABLING
.Changed in version 1.0: This method used to be responsible both for internal cleanup and the cleanup of the subclass. Starting in Djblets 1.0, internal cleanup has moved to
disable_hook()
. Subclasses no longer need to call the parent method unless inheriting from a mixin or anotherExtensionHook
subclass, but should continue to do so if they need to retain compatibility with older versions.Example
@six.add_metaclass(ExtensionHookPoint) class ThingHook(ExtensionHook): def shutdown(self): unregister_thing(self.thing_id)
-
enable_hook
(*args, **kwargs)[source]¶ Enable the ExtensionHook, beginning the initialization process.
This will register the instance of the hook and begin its initialization. It takes the same parameters that would be given during construction of the hook, allowing disabled hooks to be created again with fresh state.
Subclasses should not override this process. They should instead implement
initialize()
to handle initialization of the state of the hook.New in version 1.0.
Parameters:
-
disable_hook
(call_shutdown=True)[source]¶ Disable the hook, unregistering it from the extension.
This will unregister the hook and uninitialize it, putting it into a disabled state.
Consumers can call this if they want to turn off hooks temporarily without reconstructing the instances later. It’s also called internally when shutting down an extension.
New in version 1.0.
Parameters: call_shutdown (bool, optional) – Whether to call shutdown()
. This should always beTrue
unless called internally.
-
-
class
SignalHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
Connects to a Django signal.
This will handle connecting to a signal, calling the specified callback when fired. It will disconnect from the signal when the extension is disabled.
The callback will also be passed an extension= keyword argument pointing to the extension instance.
-
initialize
(signal, callback, sender=None, sandbox_errors=True)[source]¶ Initialize the hook.
Parameters: - signal (django.dispatch.Signal) – The signal to connect to.
- callback (callable) – The function to call when the signal is fired.
- sender (object or class, optional) – The sender argument to pass to the signal connection.
See
send()
for more information. - sandbox_errors (bool, optional) – If
True
, errors coming fromcallback
will be sandboxed, preventing them from reaching the code that fired the signal. The error will instead be logged and then ignored.
-
-
class
TemplateHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.AppliesToURLMixin
,djblets.extensions.hooks.ExtensionHook
Custom templates hook.
A hook that renders a template at hook points defined in another template.
-
initialize
(name, template_name=None, apply_to=[], extra_context={})[source]¶ Initialize the hook.
Parameters: - name (unicode) – The name of the template hook point that should render this template. This is application-specific.
- template_name (unicode, optional) – The name of the template to render.
- apply_to (list, optional) – The list of URL names where this template should render. By default, all templates containing the template hook point will render this template.
- extra_context (dict) – Extra context to include when rendering the template.
-
render_to_string
(request, context)[source]¶ Renders the content for the hook.
By default, this renders the provided template name to a string and returns it.
-
-
class
URLHook
(extension, *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
Custom URL hook.
A hook that installs custom URLs. These URLs reside in a project-specified parent URL.