reviewboard.extensions.hooks¶
-
class
AuthBackendHook
(extension, backend_cls)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for registering an authentication backend.
Authentication backends control user authentication, registration, and user lookup, and user data manipulation.
This hook takes the class of an authentication backend that should be made available to the server.
-
class
AccountPagesHook
(extension, page_classes)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
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.
-
class
AccountPageFormsHook
(extension, page_id, form_classes)[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.
-
class
AdminWidgetHook
(extension, widget_cls, primary=False)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for adding a new widget to the admin screen.
By default the new widget is added as a small widget in the right column of the admin page. To instead add the new widget as a large widget in the center of the admin page, pass in True for
primary
.
-
class
DataGridSidebarItemsHook
(extension, datagrid, item_classes)[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
.
-
class
DashboardColumnsHook
(extension, columns)[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, item_classes)[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
.
-
class
HostingServiceHook
(extension, service_cls)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for registering a hosting service.
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 displayurl
: 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.
-
class
ReviewRequestApprovalHook
(extension)[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]¶ Determines 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.
-
-
class
ReviewRequestFieldSetsHook
(extension, fieldsets)[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.
-
class
ReviewRequestFieldsHook
(extension, fieldset_id, fields)[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.
-
class
WebAPICapabilitiesHook
(extension, caps)[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.
-
class
CommentDetailDisplayHook
(extension)[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.
-
class
ReviewUIHook
(extension, review_uis)[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.
-
class
FileAttachmentThumbnailHook
(extension, mimetype_handlers)[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 MimetypeHandlers are registered when the hook is created. Likewise, it unregisters the same list of MimetypeHandlers when the Extension is disabled.
- Subclass
-
class
ActionHook
(extension, actions=[], *args, **kwargs)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
A hook for adding actions to a review request.
Actions are displayed somewhere on the action bar (alongside Reviews, Close, etc.) of the review request. The subclasses of ActionHook should be used to determine placement.
The provided actions parameter must be a list of actions. Each action must be a dict with the following keys:
id
: The ID of this action (optional).image
: The path to the image used for the icon (optional).image_width
: The width of the image (optional).image_height
: The height of the image (optional).label
: The label for the action.url
: The URI to invoke when the action is clicked.- If you want to invoke a javascript action, this should be ‘#’, and you should use a selector on the id field to attach the handler (as opposed to a javascript: URL, which doesn’t work on all browsers).
If your hook needs to access the template context, it can override get_actions and return results from there.
-
class
ReviewRequestActionHook
(extension, actions=[], *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ActionHook
A hook for adding an action to the review request page.
-
class
ReviewRequestDropdownActionHook
(extension, actions=[], *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ActionHook
A hook for adding an drop down action to the review request page.
The actions for a drop down action should contain:
id
: The ID of this action (optional).label
: The label of the drop-down.items
: A list of ActionHook-style dicts (see ActionHook params).
For example:
actions = [{ 'id': 'id 0', 'label': 'Title', 'items': [ { 'id': 'id 1', 'label': 'Item 1', 'url': '...', }, { 'id': 'id 2', 'label': 'Item 2', 'url': '...', } ] }]
-
class
DiffViewerActionHook
(extension, actions=[], *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ActionHook
A hook for adding an action to the diff viewer page.
-
class
HeaderActionHook
(extension, actions=[], *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ActionHook
A hook for putting an action in the page header.
-
class
HeaderDropdownActionHook
(extension, actions=[], *args, **kwargs)[source]¶ Bases:
reviewboard.extensions.hooks.ActionHook
A hook for putting multiple actions into a header dropdown.
-
class
UserPageSidebarItemsHook
(extension, item_classes)[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
.
-
class
EmailHook
(extension, signals=None)[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 sub-classed instead.
ReviewPublishedEmailHook
ReviewReplyPublishedEmailHook
ReviewRequestPublishedEmailHook
ReviewRequestClosedEmailHook
However, if more specialized behaviour is desired, this class can be sub-classed.
-
__init__
(extension, signals=None)[source]¶ Initialize the EmailHook.
Parameters: - extension (reviewboard.extensions.base.Extension) – The extension creating this hook.
- 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)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review publishing e-mails.
-
__init__
(extension)[source]¶ Initialize the ReviewPublishedEmailHook.
Parameters: extension (reviewboard.extensions.base.Extension) – The extension registering this hook.
-
get_to_field
(to_field, review, user, review_request)[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.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, review, user, review_request)[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 (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.
Returns: The desired CC field.
Return type: - to_field (set) – A set of
-
-
class
ReviewReplyPublishedEmailHook
(extension)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review reply publishing e-mails.
-
__init__
(extension)[source]¶ Initialize the ReviewReplyPublishedEmailHook.
Parameters: extension (djblets.extensions.Extension) – The extension registering this hook.
-
get_to_field
(to_field, reply, user, review_request)[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.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, reply, user, review_request)[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.
Returns: The desired CC field.
Return type: - to_field (set) – A set of
-
-
class
ReviewRequestClosedEmailHook
(extension)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review request closing e-mails.
-
__init__
(extension)[source]¶ Initialize the ReviewRequestClosedEmailHook.
Parameters: extension (reviewboard.extensions.base.Extension) – The extension registering this hook.
-
get_to_field
(to_field, review_request, user, close_type)[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
.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, review_request, user, close_type)[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
.
Returns: The desired CC field.
Return type: - to_field (set) – A set of
-
-
class
ReviewRequestPublishedEmailHook
(extension)[source]¶ Bases:
reviewboard.extensions.hooks.EmailHook
A hook for changing the recipients of review request publishing e-mails.
-
__init__
(extension)[source]¶ Initialize the ReviewRequestPublishedEmailHook.
Parameters: extension (reviewboard.extensions.base.Extension) – The extension registering this hook.
-
get_to_field
(to_field, review_request, user)[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.
Returns: The desired To field.
Return type: - to_field (set) – A set of
-
get_cc_field
(cc_field, review_request, user)[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.
Returns: The desired CC field.
Return type: - to_field (set) – A set of
-
-
class
DataGridColumnsHook
(extension, datagrid_cls, columns)[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)[source]¶ Bases:
object
The base class for a hook into some part of the project.
ExtensionHooks are classes that can hook into an
ExtensionHookPoint
to provide some level of functionality in a project. A project should provide a subclass of ExtensionHook that will provide functions for getting data or anything else that’s needed, and then extensions will subclass that specific ExtensionHook.A base ExtensionHook subclass must use
ExtensionHookPoint
as a metaclass. For example:from django.utils import six @six.add_metaclass(ExtensionHookPoint) class NavigationHook(ExtensionHook):
-
class
SignalHook
(extension, signal, callback, sender=None, sandbox_errors=True)[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.
-
class
TemplateHook
(extension, name, template_name=None, apply_to=[], extra_context={})[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.
-
get_extra_context
(request, context)[source]¶ Returns extra context for the hook.
Subclasses can override this to provide additional context dynamically beyond what’s passed in to the constructor.
By default, an empty dictionary is returned.
-