fairdm.contrib.plugins.checks#

Registration-time validation that refuses a plugin registration that cannot work.

Validation runs in the decorator rather than in Django’s check framework, because checks only run from management commands and would never fire on a production boot.

Module Contents#

Functions#

validate_models

Require at least one model and that each is a Django model class.

validate_check

Require check to be a bool or a callable the access decision can evaluate.

validate_segment

Require a path segment to be usable in a route.

validate_extra_views

Require additional views to be plugins that do not collide, nest or claim the plugin’s own address.

url_names_for

List every URL name the plugin will generate.

validate_against_existing

Require names, segments and generated URL names to be unique for one record type.

validate_registration

Run every check possible when a plugin is registered against one record type.

API#

exception PluginRegistrationError[source]#

Bases: django.core.exceptions.ImproperlyConfigured

A plugin registration that cannot work.

Initialization

Initialize self. See help(type(self)) for accurate signature.

validate_models(plugin_class: type[fairdm.contrib.plugins.base.Plugin], models: tuple[Any, ...]) → None[source]#

Require at least one model and that each is a Django model class.

Refusal raises PluginRegistrationError.

Args: plugin_class: The plugin being registered. models: The values given to the decorator.

validate_check(plugin_class: type[fairdm.contrib.plugins.base.Plugin], model: Any) → None[source]#

Require check to be a bool or a callable the access decision can evaluate.

A classmethod is refused because it is truthy but not callable, so it would permit every request.

A failing check raises PluginRegistrationError.

Args: plugin_class: The plugin being registered. model: The record type it is registered against.

validate_segment(plugin_class: type[fairdm.contrib.plugins.base.Plugin], model: Any, segment: str) → None[source]#

Require a path segment to be usable in a route.

A segment Django rejects raises PluginRegistrationError.

Args: plugin_class: The plugin being registered. model: The record type it is registered against. segment: The URL path segment.

validate_extra_views(plugin_class: type[fairdm.contrib.plugins.base.Plugin], model: Any) → None[source]#

Require additional views to be plugins that do not collide, nest or claim the plugin’s own address.

A violation raises PluginRegistrationError.

Args: plugin_class: The plugin being registered. model: The record type it is registered against.

url_names_for(plugin_class: type[fairdm.contrib.plugins.base.Plugin]) → list[str][source]#

List every URL name the plugin will generate.

Args: plugin_class: The plugin.

Returns: The plugin’s own name followed by one name per additional view.

validate_against_existing(plugin_class: type[fairdm.contrib.plugins.base.Plugin], model: Any, existing: list[tuple[type[fairdm.contrib.plugins.base.Plugin], dict]]) → None[source]#

Require names, segments and generated URL names to be unique for one record type.

A clash raises PluginRegistrationError.

Args: plugin_class: The plugin being registered. model: The record type it is registered against. existing: The (plugin class, options) entries already registered for it.

validate_registration(plugin_class: type[fairdm.contrib.plugins.base.Plugin], model: Any, existing: list[tuple[type[fairdm.contrib.plugins.base.Plugin], dict]]) → None[source]#

Run every check possible when a plugin is registered against one record type.

A registration that cannot work raises PluginRegistrationError.

Args: plugin_class: The plugin being registered. model: The record type it is registered against. existing: The (plugin class, options) entries already registered for it.