Jump to >

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.

__init__(extension, backend_cls)[source]
shutdown()[source]
hooks = [][source]
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.

__init__(extension, page_classes)[source]
shutdown()[source]
hooks = [][source]
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.

__init__(extension, page_id, form_classes)[source]
shutdown()[source]
hooks = [][source]
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.

__init__(extension, widget_cls, primary=False)[source]
shutdown()[source]
hooks = [][source]
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-in reviewboard.datagrids.sidebar.BaseSidebarSection and built-in reviewboard.datagrids.sidebar.SidebarNavItem.

__init__(extension, datagrid, item_classes)[source]
shutdown()[source]
hooks = [][source]
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 of djblets.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.

__init__(extension, columns)[source]
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-in reviewboard.datagrids.sidebar.BaseSidebarSection and built-in reviewboard.datagrids.sidebar.SidebarNavItem.

__init__(extension, item_classes)[source]
class HostingServiceHook(extension, service_cls)[source]

Bases: djblets.extensions.hooks.ExtensionHook

A hook for registering a hosting service.

__init__(extension, service_cls)[source]
shutdown()[source]
hooks = [][source]
class NavigationBarHook(extension, entries={}, is_enabled_for=None, *args, **kwargs)[source]

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 or url_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.

__init__(extension, entries={}, is_enabled_for=None, *args, **kwargs)[source]
get_entries(context)[source]
hooks = [][source]
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.

hooks = [][source]
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.

__init__(extension, fieldsets)[source]
shutdown()[source]
hooks = [][source]
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.

__init__(extension, fieldset_id, fields)[source]
shutdown()[source]
hooks = [][source]
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.

__init__(extension, caps)[source]
shutdown()[source]
hooks = [][source]
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.

render_review_comment_detail(comment)[source]
render_email_comment_detail(comment, is_html)[source]
hooks = [][source]
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.

__init__(extension, review_uis)[source]
shutdown()[source]
hooks = [][source]
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.

__init__(extension, mimetype_handlers)[source]
shutdown()[source]
hooks = [][source]
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.

__init__(extension, actions=[], *args, **kwargs)[source]
get_actions(context)[source]

Returns the list of action information for this action.

class ReviewRequestActionHook(extension, actions=[], *args, **kwargs)[source]

Bases: reviewboard.extensions.hooks.ActionHook

A hook for adding an action to the review request page.

hooks = [][source]
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': '...',
        }
    ]
}]
hooks = [][source]
class DiffViewerActionHook(extension, actions=[], *args, **kwargs)[source]

Bases: reviewboard.extensions.hooks.ActionHook

A hook for adding an action to the diff viewer page.

hooks = [][source]
class HeaderActionHook(extension, actions=[], *args, **kwargs)[source]

Bases: reviewboard.extensions.hooks.ActionHook

A hook for putting an action in the page header.

hooks = [][source]
class HeaderDropdownActionHook(extension, actions=[], *args, **kwargs)[source]

Bases: reviewboard.extensions.hooks.ActionHook

A hook for putting multiple actions into a header dropdown.

hooks = [][source]
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-in reviewboard.datagrids.sidebar.BaseSidebarSection and built-in reviewboard.datagrids.sidebar.SidebarNavItem.

__init__(extension, item_classes)[source]
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.

However, if more specialized behaviour is desired, this class can be sub-classed.

__init__(extension, signals=None)[source]

Initialize the EmailHook.

Parameters:
shutdown()[source]

Unregister the e-mail handlers.

get_to_field(to_field, **kwargs)[source]

Return the To field for the e-mail.

Parameters:
  • to_field (set) – A set of Users and Groups that will receive the e-mail.
  • kwargs (dict) – Additional keyword arguments that will be passed based on the type of e-mail being sent.
Returns:

The desired To field.

Return type:

set

get_cc_field(cc_field, **kwargs)[source]

Return the CC field for the e-mail.

Parameters:
  • cc_field (set) – A set of Users and Groups that will receive a carbon copy of the e-mail.
  • kwargs (dict) – Additional keyword arguments that will be passed based on the type of e-mail being sent.
Returns:

The desired CC field.

Return type:

set

hooks = [][source]
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:
Returns:

The desired To field.

Return type:

set

get_cc_field(cc_field, review, user, review_request)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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:
Returns:

The desired To field.

Return type:

set

get_cc_field(cc_field, reply, user, review_request)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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:
Returns:

The desired To field.

Return type:

set

get_cc_field(cc_field, review_request, user, close_type)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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:
Returns:

The desired To field.

Return type:

set

get_cc_field(cc_field, review_request, user)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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.

__init__(extension, datagrid_cls, columns)[source]
hooks = [][source]
shutdown()[source]
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):
__init__(extension)[source]
shutdown()[source]
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.

__init__(extension, signal, callback, sender=None, sandbox_errors=True)[source]
hooks = [][source]
shutdown()[source]
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.

__init__(extension, name, template_name=None, apply_to=[], extra_context={})[source]
classmethod by_name(name)[source]
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.

hooks = [][source]
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.

shutdown()[source]
class URLHook(extension, patterns)[source]

Bases: djblets.extensions.hooks.ExtensionHook

Custom URL hook.

A hook that installs custom URLs. These URLs reside in a project-specified parent URL.

__init__(extension, patterns)[source]
hooks = [][source]
shutdown()[source]