Jump to >

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.

registry = <reviewboard.accounts.backends.registry.AuthBackendRegistry object>[source]
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.
hooks = [][source]
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.

registry = <reviewboard.avatars.registry.AvatarServiceRegistry object>[source]
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.

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

registry = <reviewboard.accounts.pages.AccountPageRegistry object>[source]
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.
hooks = [][source]
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.
shutdown()[source]

Shut down the hook.

This will unregister each of the page form classes from the associated page.

hooks = [][source]
class AdminWidgetHook(extension, *args, **kwargs)[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.

initialize(widget_cls, primary=False)[source]

Initialize the hook.

This will register the provided administration widget as either a primary or secondary widget.

Parameters:
  • widget_cls (type) – The widget class to register. This must be a subclass of Widget.
  • primary (bool, optional) – Whether this is a primary or a secondary widget. Primary widgets are displayed first and more prominently.
Raises:
  • KeyError – The widget was already registered.
  • ValueError – The widget is missing an ID.
shutdown()[source]

Shut down the hook.

This will unregister the administration widget.

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

shutdown()[source]

Shut down the hook.

This will unregister each item class from the datagrid’s sidebar.

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

initialize(columns)[source]

Initialize the hook.

This will register each of the provided columns on the Dashboard.

Parameters:columns (list of djblets.datagrid.grids.Column) – The list of column instances to register on the Dashboard.
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-in reviewboard.datagrids.sidebar.BaseSidebarSection and built-in reviewboard.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.
shutdown()[source]

Shut down the hook.

This will unregister the hosting service.

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

hooks = [][source]
class NavigationBarHook(extension, *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.

initialize(entries=[], is_enabled_for=None, *args, **kwargs)[source]

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.
get_entries(context)[source]

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

bool or tuple

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

Shut down the hook.

This will unregister each of the fieldsets from the review requests.

hooks = [][source]
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:
shutdown()[source]

Shut down the hook.

This will unregister each of the field classes from the fieldset.

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

Shut down the hook.

This will unregister each of the capabilities from the API.

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

django.utils.safestring.SafeText

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

Shut down the hook.

This will unregister the list of review UIs.

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

Shut down the hook.

This will unregister each of the mimetype handler classes.

hooks = [][source]
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 a dict 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 the id field to attach the handler (as opposed to a javascript: 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 or BaseReviewRequestAction) to be added.
  • *args (tuple) – Extra positional arguments.
  • **kwargs (dict) – Extra keyword arguments.
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 subclass BaseReviewRequestMenuAction). For backwards compatibility, actions may also be supplied as ActionHook-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 or BaseReviewRequestAction) 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:
shutdown()[source]

Shutdown the hook and unregister all actions.

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 an ActionHook-style dictionary.
hooks = [][source]
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 or BaseReviewRequestAction) 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:
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 a ReviewRequestDropdownActionHook-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 or BaseReviewRequestAction) to be added.
  • apply_to (list of unicode, optional) – The list of URL names that this action hook will apply to.
Raises:
class HeaderActionHook(extension, *args, **kwargs)[source]

Bases: reviewboard.extensions.hooks.ActionHook

A hook for adding actions to the page header.

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

Bases: reviewboard.extensions.hooks.ActionHook

A hook for adding dropdown menu actions to the page header.

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

Additional context to include when rendering the template.

Return type:

dict

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

Text to include in the infobox HTML.

Return type:

django.utils.safestring.SafeText

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

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:

shutdown()[source]

Shut down the hook.

This will unregister each of 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, *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/or get_cc_field().

initialize()[source]

Initialize the hook.

get_to_field(to_field, review, user, review_request, to_owner_only, **kwargs)[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, to_owner_only, **kwargs)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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/or get_cc_field().

initialize()[source]

Initialize the hook.

get_to_field(to_field, reply, user, review_request, **kwargs)[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, **kwargs)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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/or get_cc_field().

initialize()[source]

Initialize the hook.

get_to_field(to_field, review_request, user, close_type, **kwargs)[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, **kwargs)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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/or get_cc_field().

initialize()[source]

Initialize the hook.

get_to_field(to_field, review_request, user, **kwargs)[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, **kwargs)[source]

Return the CC field for the e-mail.

Parameters:
Returns:

The desired CC field.

Return type:

set

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 of WebAPIResource.

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 of field_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 a tuple) and the second is the field’s access state (as one of ACCESS_STATE_PUBLIC or ACCESS_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:
get_extra_data_state(key_path)[source]

Return the state of an extra_data field.

Parameters:key_path (tuple) – A tuple of strings representing the path of an extra_data field.
Returns:The access state of the provided field or None.
Return type:int
shutdown()[source]

Shut down the hook.

This will unregister the access levels from the resource.

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

Bases: djblets.extensions.hooks.BaseRegistryHook

Registers a ConsentRequirement for use of personal data.

registry[source]

The registry that the hook interfaces with.

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

initialize(datagrid_cls, columns)[source]

Initialize the hook.

Parameters:
  • datagrid_cls (type) – The specific datagrid class that will include this registered list of columns as possible options.
  • columns (list) – A list of Column instances to register on the datagrid.
shutdown()[source]
hooks = [][source]
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 parent shutdown() method, either. However, to retain compatibility with older versions, they may still override __init__() and may call the parent shutdown(). See those methods for more details.

extension

djblets.extensions.extension.Extension – The parent extension, or another object that can act as a hook owner.

hook_state

int – The state of the hook. This will be one of HOOK_STATE_DISABLED, HOOK_STATE_ENABLED, HOOK_STATE_DISABLING, or HOOK_STATE_ENABLING.

HOOK_STATE_DISABLED = 0[source]

The hook is disabled.

HOOK_STATE_ENABLED = 1[source]

The hook is enabled.

HOOK_STATE_DISABLING = 2[source]

The hook is in the process of disabling.

HOOK_STATE_ENABLING = 3[source]

The hook is in the process of enabling.

__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 call initialize(), 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 to initialize().

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

Whether the hook is initialized and enabled.

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 to HOOK_STATE_ENABLING.

By default, this does nothing.

New in version 1.0.

Parameters:
  • *args (tuple) – The list of additional arguments used to initialize the hook state.
  • **kwargs (dict) – The additional keyword arguments used to initialize the hook state.

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 to HOOK_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 another ExtensionHook 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:
  • *args (tuple) – The list of additional arguments used to initialize the hook state.
  • **kwargs (dict) – The additional keyword arguments used to initialize the hook state.
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 be True 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 from callback will be sandboxed, preventing them from reaching the code that fired the signal. The error will instead be logged and then ignored.
shutdown()[source]
hooks = [][source]
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.
shutdown()[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.

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.

classmethod by_name(name)[source]
hooks = [][source]
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.

initialize(patterns)[source]

Initialize the hook.

Parameters:patterns (list) – The list of url() entries comprising the URLs to register.
shutdown()[source]
hooks = [][source]