Jump to >


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

class NavigationHook(ExtensionHook):
class ExtensionHookPoint(name, bases, attrs)[source]

Bases: type

A metaclass used for base Extension Hooks.

Base ExtensionHook classes use ExtensionHookPoint as a metaclass. This metaclass stores the list of registered hooks that an ExtensionHook will automatically register with.

__init__(name, bases, attrs)[source]

Adds an ExtensionHook to the list of active hooks.

This is called automatically by ExtensionHook.


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.

__init__(extension, apply_to=[], *args, **kwargs)[source]

Returns whether or not this hook applies to the page.

This will determine whether any of the URL names provided in apply_to matches the current requested 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.

__init__(extension, datagrid_cls, columns)[source]
hooks = [][source]
class URLHook(extension, patterns)[source]

Bases: djblets.extensions.hooks.ExtensionHook

Custom URL hook.

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

__init__(extension, patterns)[source]
hooks = [][source]
class SignalHook(extension, signal, callback, sender=None, sandbox_errors=True)[source]

Bases: djblets.extensions.hooks.ExtensionHook

Connects to a Django signal.

This will handle connecting to a signal, calling the specified callback when fired. It will disconnect from the signal when the extension is disabled.

The callback will also be passed an extension= keyword argument pointing to the extension instance.

__init__(extension, signal, callback, sender=None, sandbox_errors=True)[source]
hooks = [][source]
class TemplateHook(extension, name, template_name=None, apply_to=[], extra_context={})[source]

Bases: djblets.extensions.hooks.AppliesToURLMixin, djblets.extensions.hooks.ExtensionHook

Custom templates hook.

A hook that renders a template at hook points defined in another template.

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