djblets.extensions.hooks¶
-
class
ExtensionHook
(extension)[source]¶ Bases:
object
The base class for a hook into some part of the project.
ExtensionHooks are classes that can hook into an
ExtensionHookPoint
to provide some level of functionality in a project. A project should provide a subclass of ExtensionHook that will provide functions for getting data or anything else that’s needed, and then extensions will subclass that specific ExtensionHook.A base ExtensionHook subclass must use
ExtensionHookPoint
as a metaclass. For example:from django.utils import six @six.add_metaclass(ExtensionHookPoint) class NavigationHook(ExtensionHook):
-
class
ExtensionHookPoint
(name, bases, attrs)[source]¶ Bases:
type
A metaclass used for base Extension Hooks.
Base
ExtensionHook
classes useExtensionHookPoint
as a metaclass. This metaclass stores the list of registered hooks that anExtensionHook
will automatically register with.-
add_hook
(hook)[source]¶ Adds an ExtensionHook to the list of active hooks.
This is called automatically by
ExtensionHook
.
-
remove_hook
(hook)[source]¶ Removes an ExtensionHook from the list of active hooks.
This is called automatically by
ExtensionHook
.
-
-
class
AppliesToURLMixin
(extension, apply_to=[], *args, **kwargs)[source]¶ Bases:
object
A mixin for hooks to allow restricting to certain URLs.
This provides an applies_to() function for the hook that can be used by consumers to determine if the hook should apply to the current page.
-
class
DataGridColumnsHook
(extension, datagrid_cls, columns)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
Adds columns to a datagrid.
This hook allows an extension to register new columns to any datagrid. These columns can be added by the user, rearranged, and sorted, like any other column.
Each column must have an id already set, and it must be unique.
-
class
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.
-
class
SignalHook
(extension, signal, callback, sender=None, sandbox_errors=True)[source]¶ Bases:
djblets.extensions.hooks.ExtensionHook
Connects to a Django signal.
This will handle connecting to a signal, calling the specified callback when fired. It will disconnect from the signal when the extension is disabled.
The callback will also be passed an extension= keyword argument pointing to the extension instance.
-
class
TemplateHook
(extension, name, template_name=None, apply_to=[], extra_context={})[source]¶ Bases:
djblets.extensions.hooks.AppliesToURLMixin
,djblets.extensions.hooks.ExtensionHook
Custom templates hook.
A hook that renders a template at hook points defined in another template.
-
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.
-