fairdm.contrib.plugins.base#
Plugin mixin base class for extending model detail views.
Module Contents#
Classes#
Mixin that turns a Django class-based view into a page attached to a core record. |
API#
- class Plugin(**kwargs)#
Bases:
django.contrib.auth.mixins.PermissionRequiredMixin,django.views.generic.base.ViewMixin that turns a Django class-based view into a page attached to a core record.
Attributes: registered_model: The model this mount serves. Bound per mount by
as_view, so a plugin registered against two models serves each independently. plugin_class: The plugin that owns this view. None on every class, a plugin’s and an additional view’s alike.as_viewbinds the declaring plugin on the instance of an additional view. Access is not read from it: each view is decided by its owncheckandpermission. name: Unique identifier per model. Defaults to the slugified class name. url_path: URL path segment.""uses the name,Nonemounts without a base path, and any other string is used as given. permission: Permission or permissions required to open the page. check: Predicate(request, obj)or bool deciding whether the page opens. model: The base model, set by the registry during registration. menu: The navigation menu bound per mount byas_view. extra_views: Additional view classes belonging to this plugin. Read throughget_extra_views. page_title: Last entry of the breadcrumb trail (#112). slug_field: Model field used to find the record. slug_url_kwarg: URL keyword argument holding the record’s slug.Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- plugin_class: ClassVar[type[fairdm.contrib.plugins.base.Plugin] | None]#
None
- name: ClassVar[str | None]#
None
- url_path: ClassVar[str | None] = <Multiline-String>#
- permission: ClassVar[str | None]#
None
- check: ClassVar[collections.abc.Callable[[django.http.HttpRequest, django.db.models.Model | None], bool] | None]#
True
None
- extra_views: ClassVar[list[type[fairdm.contrib.plugins.base.Plugin]]]#
[]
- page_title: ClassVar[str] = <Multiline-String>#
- slug_field#
‘uuid’
- slug_url_kwarg#
‘uuid’
- classmethod get_name() str#
Return the plugin name, the slugified class name unless
nameis set.Returns: The name used for URL naming and identification.
- classmethod get_url_path() str | None#
Return the URL path segment.
Returns: The segment, such as
"analysis", or None whenurl_pathis None (no base path).
- classmethod get_extra_views() list[type[fairdm.contrib.plugins.base.Plugin]]#
Return the additional view classes belonging to this plugin.
Returns: A new list copied from
extra_views.
- classmethod get_urls(menu_class=None, model=None) list[django.urls.URLPattern]#
Build one flat URL pattern for the plugin and one for each view it owns.
Patterns are named
<plugin>and<plugin>-<child>, with no nested namespace.Args: menu_class: The menu bound to each mount. model: The model bound to each mount, so one plugin registered against two records serves each independently.
Returns: The URL patterns.
- base_object() django.db.models.Model | None#
The core record this plugin hangs from, or None when it cannot be resolved.
Distinct from
self.object, which the view class manages for itself.
- get_base_object() django.db.models.Model#
Fetch the core record named by the address, using the model’s declared addressing.
Returns: The record.
Raises: ValueError: The mount has no model, or none of the model’s lookup kwargs are in the URL.
- get_queryset()#
Read through the served model’s
all_objectsmanager, asget_base_objectdoes.
- has_permission() bool#
Decide with :func:
~fairdm.contrib.plugins.access.can_open, as the navigation entry does.
- get_context_data(**kwargs: Any) dict[str, Any]#
Add the core record, breadcrumbs, the plugin menu and the plugin’s media.
- get_breadcrumbs() list[dict[str, Any]]#
Build the breadcrumb trail from the model, the record and the page title.
Returns: Breadcrumb dicts with a
textkey and, where a link resolves, anhref.