fairdm.contrib.plugins.registration#
Plugin registry for managing plugin/model associations.
Module Contents#
Classes#
Track which plugins are registered for each model and how records are addressed. |
Data#
API#
- class PluginRegistry[source]#
Track which plugins are registered for each model and how records are addressed.
The registry builds each model’s URL patterns and navigation menu.
Attributes: DEFAULT_ROUTE: The route fragment for a record when its model declares none. DEFAULT_LOOKUP: The URL kwarg to model field map used when its model declares none.
Example: Register a plugin for a model::
from fairdm import plugins @plugins.register(Sample, label="My Plugin", icon="star", order=10) class MyPlugin(Plugin, TemplateView): ...Initialization
- DEFAULT_LOOKUP: ClassVar[dict[str, str]]#
None
- register(*models: type[django.db.models.Model], **kwargs)[source]#
Return a decorator that registers a plugin with one or more models.
Args: *models: The base model classes to register the plugin against. **kwargs: Registration options such as
label,icon,orderandmenu, kept with the plugin for building its navigation entry.Returns: A decorator that adds the plugin class to the registry and returns it.
Example: Restrict a plugin to one subtype::
@plugins.register(Sample) class AnalysisPlugin(Plugin, TemplateView): check = is_instance_of(RockSample)
- declare_addressing(model: type[django.db.models.Model], route: str, lookup: dict[str, str]) None[source]#
Declare how a record of
modelappears in an address.Args: model: The record type. route: The route fragment, such as
"<str:lon>/<str:lat>". lookup: URL kwarg to model field, such as{"lon": "x", "lat": "y"}.Raises: ValueError: A lookup name is not captured by the route.
- get_addressing(model: type[django.db.models.Model]) tuple[str, dict[str, str]][source]#
Return the route fragment and lookup map for a record type.
Args: model: The record type.
Returns: The declared
(route, lookup)pair, or the defaults.
- route_for(model: type[django.db.models.Model]) str[source]#
Return the route fragment a URL configuration mounts this record’s plugins beneath.
Args: model: The record type.
Returns: The route fragment.
- lookup_for(model: type[django.db.models.Model]) dict[str, str][source]#
Return the URL kwarg to model field map for resolving and reversing a record.
Args: model: The record type.
Returns: The lookup map.
- get_plugins_for_model(model: type[django.db.models.Model]) list[type[fairdm.contrib.plugins.base.Plugin]][source]#
Return the plugins registered for a model.
Args: model: The model class.
Returns: The registered
(plugin class, options)entries, empty when there are none.
Return the navigation menu for a record type, creating it on first use.
Args: model: The record type.
Returns: The menu named
<Model>Menu.
- get_urls_for_model(model: type[django.db.models.Model]) list[django.urls.URLPattern][source]#
Collect the URL patterns of every plugin registered for a model and build its menu.
Args: model: The model class.
Returns: URL patterns suitable for
include().
- configure_tab(plugin_class: type[fairdm.contrib.plugins.base.Plugin], model: type[django.db.models.Model], **kwargs) flex_menu.MenuItem[source]#
Build the navigation entry for a registration.
Args: plugin_class: The registered plugin. model: The model it is registered against. **kwargs: The registration options:
label,iconandorder.Returns: The menu item, visible only when the plugin’s page opens.
Order a record’s entries by declared position rather than registration order.
Args: menu: The menu to sort in place.
- registry#
‘PluginRegistry(…)’