reviewboard.extensions.hooks¶
Extension hooks for Review Board.
- class APIExtraDataAccessHook(extension: Extension, *args, **kwargs)¶
Bases:
ExtensionHook
A hook for setting access states on 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)¶
Initialize the APIExtraDataAccessHook.
- Parameters:
resource (
reviewboard.webapi.base.WebAPIResource
) – The resource to modify access states for.field_set (
list
) – Each element offield_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
).
- get_extra_data_state(key_path)¶
Return the state of an extra_data field.
- shutdown()¶
Shut down the hook.
This will unregister the access levels from the resource.
- __annotations__ = {}¶
- hooks = []¶
- class AccountPageFormsHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
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 registeredAccountPage
.form_classes (
list
oftype
) – The list of form classes to register on the page. Each class must be a subclass ofAccountPageForm
.
- shutdown()¶
Shut down the hook.
This will unregister each of the page form classes from the associated page.
- __annotations__ = {}¶
- hooks = []¶
- class AccountPagesHook(extension: Extension, *args, **kwargs)¶
Bases:
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: Optional[Registry[RegistryItemType]] = <reviewboard.accounts.pages.AccountPageRegistry object>¶
The registry to register items with.
- initialize(page_classes)¶
Initialize the hook.
This will register each of the provided account page classes.
- Parameters:
page_classes (
list
oftype
) – The list of page classes to register. Each must be a subclass ofAccountPage
.
- __annotations__ = {'items': 'Sequence[RegistryItemType]', 'registry': 'Optional[Registry[RegistryItemType]]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- __parameters__ = ()¶
- hooks = []¶
- class ActionHook(extension: Extension, *args, **kwargs)¶
Bases:
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. These are subclasses ofreviewboard.actions.base.BaseAction
.- actions: List[BaseAction]¶
The actions registered by this hook.
- initialize(actions: Optional[List[BaseAction]] = None, *args, **kwargs) None ¶
Initialize this action hook.
- Parameters:
actions (
list
ofreviewboard.actions.base.BaseAction
, optional) – The list of actions to be added.*args (
tuple
) – Extra positional arguments.**kwargs (
dict
) – Extra keyword arguments.
- get_actions(context)¶
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:
- __annotations__ = {'actions': 'List[BaseAction]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- hooks = []¶
- class AdminWidgetHook(extension: Extension, *args, **kwargs)¶
Bases:
BaseRegistryHook
A hook for adding a new widget to the administration dashboard.
Changed in version 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.Changed in version 5.0: Support for legacy widgets and arguments has been removed.
- registry: Optional[Registry[RegistryItemType]] = <reviewboard.admin.widgets.AdminWidgetsRegistry object>¶
The registry to register items with.
- __annotations__ = {'item': 'RegistryItemType', 'registry': 'Optional[Registry[RegistryItemType]]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- __parameters__ = ()¶
- hooks = []¶
- class AuthBackendHook(extension: Extension, *args, **kwargs)¶
Bases:
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: Optional[Registry[RegistryItemType]] = <reviewboard.accounts.backends.registry.AuthBackendRegistry object>¶
The registry to register items with.
- initialize(backend_cls)¶
Initialize the hook.
This will register the provided authentication backend.
- Parameters:
backend_cls (
type
) – The authentication backend to register. This should be a subclass ofAuthBackend
.
- __annotations__ = {'item': 'RegistryItemType', 'registry': 'Optional[Registry[RegistryItemType]]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- __parameters__ = ()¶
- hooks = []¶
- class AvatarServiceHook(extension: Extension, *args, **kwargs)¶
Bases:
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: Optional[Registry[RegistryItemType]] = <SimpleLazyObject: <reviewboard.avatars.registry.AvatarServiceRegistry object>>¶
The registry to register items with.
- initialize(service)¶
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
.
- __annotations__ = {'item': 'RegistryItemType', 'registry': 'Optional[Registry[RegistryItemType]]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- __parameters__ = ()¶
- hooks = []¶
- class CommentDetailDisplayHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
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)¶
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
- __annotations__ = {}¶
- hooks = []¶
- class ConsentRequirementHook(extension: Extension, *args, **kwargs)¶
Bases:
BaseRegistryHook
Registers a ConsentRequirement for use of personal data.
- property registry¶
The registry that the hook interfaces with.
- __annotations__ = {}¶
- __parameters__ = ()¶
- hooks = []¶
- class DashboardColumnsHook(extension: Extension, *args, **kwargs)¶
Bases:
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.- initialize(columns)¶
Initialize the hook.
This will register each of the provided columns on the Dashboard.
- Parameters:
columns (
list
ofdjblets.datagrid.grids.Column
) – The list of column instances to register on the Dashboard.
- __annotations__ = {}¶
- class DashboardSidebarItemsHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
Initialize the hook.
This will register the provided datagrid sidebar item classes in the Dashboard.
- Parameters:
item_classes (
list
oftype
) – The list of item classes to register on the datagrid’s sidebar. Each must be a subclass ofBaseSidebarItem
.
- __annotations__ = {}¶
- class DataGridColumnsHook(extension: Extension, *args, **kwargs)¶
Bases:
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.
- __annotations__ = {}¶
- hooks = []¶
- class DataGridSidebarItemsHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
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
oftype
) – The list of item classes to register on the datagrid’s sidebar. Each must be a subclass ofBaseSidebarItem
.
- Raises:
ValueError – A datagrid was provided that does not contain a sidebar.
- shutdown()¶
Shut down the hook.
This will unregister each item class from the datagrid’s sidebar.
- __annotations__ = {}¶
- hooks = []¶
- class DiffViewerActionHook(extension: Extension, *args, **kwargs)¶
Bases:
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.
This hook is deprecated. New extensions should use
reviewboard.extensions.hooks.ActionHook
.- initialize(actions=[], apply_to=['view-diff', 'view-interdiff', 'view-diff-revision'])¶
Initialize this action hook.
- __annotations__ = {}¶
- class EmailHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
Initialize the hook.
- shutdown()¶
Shut down the hook.
This will unregister each of the e-mail handlers.
- get_to_field(to_field, **kwargs)¶
Return the To field for the e-mail.
- get_cc_field(cc_field, **kwargs)¶
Return the CC field for the e-mail.
- __annotations__ = {}¶
- hooks = []¶
- class ExtensionHook(extension: Extension, *args, **kwargs)¶
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 djblets.extensions.hooks import (ExtensionHook, ExtensionHookPoint) from myproject.nav import register_thing, unregister_thing_id class ThingHook(ExtensionHook, metaclass=ExtensionHookPoint): 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.
- 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:
- HOOK_STATE_DISABLED = 0¶
The hook is disabled.
- HOOK_STATE_ENABLED = 1¶
The hook is enabled.
- HOOK_STATE_DISABLING = 2¶
The hook is in the process of disabling.
- HOOK_STATE_ENABLING = 3¶
The hook is in the process of enabling.
- remove_hook: Callable[[ExtensionHook, ExtensionHook], None]¶
- __init__(extension: Extension, *args, **kwargs) None ¶
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 toTrue
.
- initialize(*args, **kwargs) None ¶
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
class ThingHook(ExtensionHook, metaclass=ExtensionHookPoint): def initialize(self, thing_id): self.thing_id = thing_id register_thing(self.thing_id)
- shutdown() None ¶
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
class ThingHook(ExtensionHook, metaclass=ExtensionHookPoint): def shutdown(self): unregister_thing(self.thing_id)
- enable_hook(*args, **kwargs) None ¶
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.
- disable_hook(call_shutdown: bool = True) None ¶
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 callshutdown()
. This should always beTrue
unless called internally.
- __annotations__ = {'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- class FileAttachmentThumbnailHook(extension: Extension, *args, **kwargs)¶
Bases:
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:
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)¶
Initialize the hook.
This will register each of the provided mimetype handler classes.
- Parameters:
mimetype_handlers (
list
oftype
) – The list of mimetype handlers to register. Each must be a subclass ofMimetypeHandler
.- Raises:
TypeError – One or more of the provided classes are not of the correct type.
- shutdown()¶
Shut down the hook.
This will unregister each of the mimetype handler classes.
- __annotations__ = {}¶
- hooks = []¶
- class FileDiffACLHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
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:
- __annotations__ = {}¶
- hooks = []¶
- class HeaderActionHook(*args, **kwargs)¶
Bases:
BaseReviewRequestActionHook
A hook for adding actions to the page header.
This hook is deprecated. New extensions should use
reviewboard.extensions.hooks.ActionHook
.The provided
actions
parameter must be a list of actions. Each action must be adict
with the following keys:id
(str
, optional):The ID to use for the action.
label
(str
):The label to use for the action.
url
(str
):The URL to link the action to.
If you want to use JavaScript to handle the action, this should be
"#"
and you should attach a handler to the element specified by the “#action-<id>” selector.image
(str
):The URL to an image to display next to the label.
image_width
(int
):The width of the image, if present.
image_height
(int
):The height of the image, if present.
- attachment = 'header'¶
- __init__(*args, **kwargs)¶
Initialize the hook.
- convert_action(action_dict)¶
Convert the given dictionary to na action instance.
- Parameters:
action_dict (
dict
) – A dictionary representing a header action.- Returns:
The corresponding review request menu action instance.
- Return type:
BaseReviewRequestMenuAction
- __annotations__ = {'actions': 'List[BaseAction]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- class HeaderDropdownActionHook(extension: Extension, *args, **kwargs)¶
Bases:
ActionHook
A hook for adding dropdown menu actions to the page header.
This hook is deprecated. New extensions should use
reviewboard.extensions.hooks.ActionHook
.The provided
actions
parameter must be a list of actions. Each action must be adict
with the following keys:id
(str
, optional):The ID to use for the action.
label
(str
):The label to use for the action.
items
(list
):A list of items, each of which is a
dict
which follows the conventions forHeaderActionHook
.
- attachment = 'header'¶
- initialize(actions=[], *args, **kwargs)¶
Initialize the hook.
- __annotations__ = {'actions': 'List[BaseAction]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- class HideActionHook(extension: Extension, *args, **kwargs)¶
Bases:
ExtensionHook
A hook for hiding built-in actions.
Extensions may want to replace built-in functionality with their own custom versions, or disable some things entirely (such as the quick ship-it button).
- __annotations__ = {'hidden_action_ids': 'List[str]'}¶
- hooks = []¶
The list of action IDs hidden by this hook.
- class HostingServiceHook(extension: Extension, *args, **kwargs)¶
Bases:
ExtensionHook
A hook for registering a hosting service.
- initialize(service_cls)¶
Initialize the hook.
This will register the hosting service.
- Parameters:
service_cls (
type
) – The hosting service class to register. This must be a subclass ofBaseHostingService
.- Raises:
ValueError – The service’s
hosting_service_id
attribute was not set.
- shutdown()¶
Shut down the hook.
This will unregister the hosting service.
- __annotations__ = {}¶
- hooks = []¶
- class IntegrationHook(extension: Extension, *args, **kwargs)¶
Bases:
GetIntegrationManagerMixin
,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.
- __annotations__ = {}¶
- hooks = []¶
Bases:
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
ofdict
) – 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:
- class ReviewPublishedEmailHook(extension: Extension, *args, **kwargs)¶
Bases:
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()
.- initialize()¶
Initialize the hook.
- get_to_field(to_field, review, user, review_request, to_owner_only, **kwargs)¶
Return the To field for the e-mail.
- Parameters:
to_field (
set
) – A set ofUsers
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:
- get_cc_field(cc_field, review, user, review_request, to_owner_only, **kwargs)¶
Return the CC field for the e-mail.
- Parameters:
cc_field (
set
) – A set ofUsers
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:
- __annotations__ = {}¶
- class ReviewReplyPublishedEmailHook(extension: Extension, *args, **kwargs)¶
Bases:
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()
.- initialize()¶
Initialize the hook.
- get_to_field(to_field, reply, user, review_request, **kwargs)¶
Return the To field for the e-mail.
- Parameters:
to_field (
set
) – A set ofUsers
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:
- get_cc_field(cc_field, reply, user, review_request, **kwargs)¶
Return the CC field for the e-mail.
- Parameters:
to_field (
set
) – A set ofUsers
andGroups
that will receive a carbon copy of the e-mailreply (
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:
- __annotations__ = {}¶
- class ReviewRequestActionHook(extension: Extension, *args, **kwargs)¶
Bases:
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.
This hook is deprecated. New extensions should use
reviewboard.extensions.hooks.ActionHook
.The provided
actions
parameter must be a list of actions. Each action must be adict
with the following keys:id
(str
, optional):The ID to use for the action.
label
(str
):The label to use for the action.
url
(str
):The URL to link the action to.
If you want to use JavaScript to handle the action, this should be
"#"
and you should attach a handler to the element specified by the “#action-<id>” selector.
- initialize(actions=[], apply_to=None)¶
Initialize this action hook.
- Parameters:
- Raises:
KeyError – Some dictionary is not an
ActionHook
-style dictionary.
- __annotations__ = {}¶
- class ReviewRequestApprovalHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
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:
- __annotations__ = {}¶
- hooks = []¶
- class ReviewRequestClosedEmailHook(extension: Extension, *args, **kwargs)¶
Bases:
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()
.- initialize()¶
Initialize the hook.
- get_to_field(to_field, review_request, user, close_type, **kwargs)¶
Return the To field for the e-mail.
- Parameters:
to_field (
set
) – A set ofUsers
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 ofSUBMITTED
orDISCARDED
.**kwargs (
dict
) – Additional keyword arguments, since the signature may change in the future.
- Returns:
The desired To field.
- Return type:
- get_cc_field(cc_field, review_request, user, close_type, **kwargs)¶
Return the CC field for the e-mail.
- Parameters:
to_field (
set
) – A set ofUsers
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 ofSUBMITTED
orDISCARDED
.**kwargs (
dict
) – Additional keyword arguments, since the signature may change in the future.
- Returns:
The desired CC field.
- Return type:
- __annotations__ = {}¶
- class ReviewRequestDropdownActionHook(extension: Extension, *args, **kwargs)¶
Bases:
ActionHook
A hook for adding dropdown menu actions to review request pages.
This hook is deprecated. New extensions should use
reviewboard.extensions.hooks.ActionHook
.The provided
actions
parameter must be a list of actions. Each action must be adict
with the following keys:id
(str
, optional):The ID to use for the action.
label
(str
):The label to use for the action.
- ‘’items`` (
list
): A list of items, each of which is a
dict
which follows the conventions forReviewRequestActionHook
.
Example
actions = [{ 'id': 'sample-menu-action', 'label': 'Sample Menu', 'items': [ { 'id': 'first-item-action', 'label': 'Item 1', 'url': '#', }, { 'label': 'Item 2', 'url': '#', }, ], }]
- attachment = 'review-request'¶
- initialize(actions=[], apply_to=None)¶
Initialize this action hook.
- Parameters:
- Raises:
KeyError – Some dictionary is not an
ActionHook
-style dictionary.
- __annotations__ = {'actions': 'List[BaseAction]', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]"}¶
- class ReviewRequestFieldSetsHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
Initialize the hook.
This will register each of the provided fieldsets for review requests.
- Parameters:
fieldsets (
list
oftype
) – The list of fieldset classes to register. Each must be a subclass ofBaseReviewRequestFieldSet
.- Raises:
djblets.registries.errors.ItemLookupError – A fieldset was already registered matching an ID from this list.
- shutdown()¶
Shut down the hook.
This will unregister each of the fieldsets from the review requests.
- __annotations__ = {}¶
- hooks = []¶
- class ReviewRequestFieldsHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
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 theBaseReviewRequestFieldSet
to register.fields (
list
oftype
) – The list of fields to register into the fieldset. Each must be a subclass ofBaseReviewRequestField
.
- shutdown()¶
Shut down the hook.
This will unregister each of the field classes from the fieldset.
- __annotations__ = {}¶
- hooks = []¶
- class ReviewRequestPublishedEmailHook(extension: Extension, *args, **kwargs)¶
Bases:
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()
.- initialize()¶
Initialize the hook.
- get_to_field(to_field, review_request, user, **kwargs)¶
Return the To field for the e-mail.
- Parameters:
to_field (
set
) – A set ofUsers
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:
- get_cc_field(cc_field, review_request, user, **kwargs)¶
Return the CC field for the e-mail.
- Parameters:
to_field (
set
) – A set ofUsers
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:
- __annotations__ = {}¶
- class ReviewUIHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
Initialize the hook.
This will register the list of review UIs for use in reviewing file attachments.
- shutdown()¶
Shut down the hook.
This will unregister the list of review UIs.
- __annotations__ = {}¶
- hooks = []¶
- class SCMToolHook(extension: Extension, *args, **kwargs)¶
Bases:
ExtensionHook
A hook for registering an SCMTool.
- initialize(scmtool_cls)¶
Initialize the hook.
This will register the SCMTool.
- Parameters:
scmtool_cls (
type
) – The SCMTool class to register. This must be a subclass ofSCMTool
.- Raises:
ValueError – The SCMTool’s
scmtool_id
attribute was not set.
- shutdown()¶
Shut down the hook.
This will unregister the SCMTool.
- __annotations__ = {}¶
- hooks = []¶
- class SignalHook(extension: Extension, *args, **kwargs)¶
Bases:
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: Signal, callback: Callable, sender: Any = None, sandbox_errors: bool = True) None ¶
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
orclass
, optional) – The sender argument to pass to the signal connection. Seesend()
for more information.sandbox_errors (
bool
, optional) – IfTrue
, 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.
- __annotations__ = {}¶
- hooks = []¶
- class TemplateHook(extension: Extension, *args, **kwargs)¶
Bases:
AppliesToURLMixin
,ExtensionHook
Custom templates hook.
A hook that renders a template at hook points defined in another template.
- initialize(name: str, template_name: Optional[str] = None, apply_to: List[str] = [], extra_context: Dict[str, Any] = {}, *args, **kwargs) None ¶
Initialize the hook.
- Parameters:
name (
str
) – The name of the template hook point that should render this template. This is application-specific.template_name (
str
, 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.*args (
tuple
) – Additional positional arguments for future expansion.**kwargs (
dict
) – Additional keyword arguments for future expansion.
- shutdown() None ¶
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
class ThingHook(ExtensionHook, metaclass=ExtensionHookPoint): def shutdown(self): unregister_thing(self.thing_id)
- render_to_string(request: HttpRequest, context: Context) str ¶
Render the content for the hook.
By default, this renders the provided template name to a string and returns it.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request.context (
django.template.Conetxt
) – The template render context.
- Returns:
Rendered content to include in the template.
- Return type:
- get_extra_context(request: HttpRequest, context: Context) Dict[str, Any] ¶
Return 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.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request.context (
django.template.Context
) – The template render context.
- Returns:
Additional context to include when rendering the template.
- Return type:
- classmethod by_name(name: str) List[TemplateHook] ¶
Return template hooks by name.
- Parameters:
name (
str
) – The name of the hook point.- Returns:
A list of all template hooks that are registered for the given name.
- Return type:
list
ofTemplateHook
- __annotations__ = {'_by_name': 'Dict[str, List[TemplateHook]]', 'extra_context': 'dict', 'name': 'str', 'remove_hook': "Callable[['ExtensionHook', ExtensionHook], None]", 'template_name': 'Optional[str]'}¶
- hooks = []¶
- class URLHook(extension: Extension, *args, **kwargs)¶
Bases:
ExtensionHook
Custom URL hook.
A hook that installs custom URLs. These URLs reside in a project-specified parent URL.
- shutdown() None ¶
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
class ThingHook(ExtensionHook, metaclass=ExtensionHookPoint): def shutdown(self): unregister_thing(self.thing_id)
- __annotations__ = {}¶
- hooks = []¶
- class UserInfoboxHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
Initialize the hook.
- get_extra_context(user, request, local_site, **kwargs)¶
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)¶
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:
- render(user, request, local_site, **kwargs)¶
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:
django.utils.safestring.SafeText
- __annotations__ = {}¶
- hooks = []¶
- class UserPageSidebarItemsHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
Initialize the hook.
This will register the provided datagrid sidebar item classes in the user page’s datagrid.
- Parameters:
item_classes (
list
oftype
) – The list of item classes to register on the datagrid’s sidebar. Each must be a subclass ofBaseSidebarItem
.
- __annotations__ = {}¶
- class WebAPICapabilitiesHook(extension: Extension, *args, **kwargs)¶
Bases:
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)¶
Initialize the hook.
This will register each of the capabilities for the API.
- shutdown()¶
Shut down the hook.
This will unregister each of the capabilities from the API.
- __annotations__ = {}¶
- hooks = []¶