fairdm.core.plugins#
Reusable overview plugins for the core record pages.
Module Contents#
Classes#
Reusable overview plugin for displaying object details. |
|
The overview of a project, dataset, sample or measurement. |
|
The overview of a record portals subclass: a sample or a measurement. |
API#
- class OverviewPlugin(**kwargs)#
Bases:
fairdm.contrib.plugins.Plugin,fairdm.views.FairDMTemplateViewReusable overview plugin for displaying object details.
This base class provides a standard overview/detail view for any model. Portal developers can inherit from this and customize:
menu: Configure tab label, icon, and order
template_name: Override the template (or use hierarchical resolution)
get_context_data(): Add custom context variables
permission: Set required permission for access
Attributes: page_subtitle: The page subtitle. page_icon: The icon shown beside the page title. menu: The tab label, icon and order.
Example: ```python from fairdm import plugins from fairdm.core.plugins import OverviewPlugin
@plugins.register(Sample) class SampleOverview(OverviewPlugin): menu = {"label": "Overview", "icon": "eye", "order": 0} template_name = "samples/sample_overview.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["measurements"] = self.base_object.measurements.all() return context ```Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- page_subtitle#
‘_(…)’
- page_icon#
‘overview’
None
- get_page_title()#
Use the object’s string representation as the page title.
- class RecordOverviewPlugin(**kwargs)#
Bases:
fairdm.core.plugins.OverviewPluginThe overview of a project, dataset, sample or measurement.
Holds what every one of those pages works out the same way: who is credited, the People card, identifiers, citation, timeline, licence entry and the two charts. A portal changes one piece of a page by subclassing that page’s plugin and overriding one of these methods.
Attributes: people_shown: How many faces the People card draws before it counts the rest. resolvable_identifier_types: The identifier types that link to doi.org.
Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- people_shown#
18
- resolvable_identifier_types#
()
- get_context_data(**kwargs)#
Lead the People card to the record’s Contributors tab and add the Manage menu.
- get_contributions() list[fairdm.contrib.contributors.models.Contribution]#
List the record’s credits, people first and then organizations, each in order.
Everything an overview or a citation names comes from this list, so they follow the order the team set on the Contributors tab.
select_relatedstops at the polymorphic base, which has neither a person’s name parts nor a way to tell the two apart, so the real instances are fetched in one extra query.Returns: The record’s contributions, each with its real contributor, roles prefetched.
- static get_role_uris(contribution) set[str]#
Give the addresses of the roles held on one credit.
Args: contribution: A contribution, from :meth:
get_contributions.Returns: The addresses of its roles.
- static get_contributors_with_role(entries, role) list[fairdm.contrib.contributors.models.Contributor]#
Pick out the contributors credited with one role.
Args: entries: The record’s credits, from :meth:
get_credits. role: The address of the role.Returns: The contributors of every entry that holds it.
- get_credits() list[dict[str, Any]]#
List everyone credited on the record.
Each contributor is its own type (person or organisation). The affiliation is the one recorded on the credit itself, so a person credited with no organization has none.
Returns: One
{"contributor", "roles": {address: label}, "affiliation"}entry per credit, in the order of :meth:get_contributions.
- get_people(entries=None) dict[str, Any]#
Work out what the People card shows.
Args: entries: The record’s credits, when the caller already has them. Defaults to :meth:
get_credits.Returns: The first
people_shownfaces, how many more there are and the total.
- get_identifiers() list[dict[str, Any]]#
List the record’s identifiers for the Identifiers card.
A DOI or an IGSN links to doi.org, since an IGSN is a DataCite DOI since 2023. A legacy IGSN handle, which does not start with
10., does not resolve there and stays unlinked.Returns: One
{"type", "value", "link"}entry per identifier,typebeing the identifier type’s concept.linkisNonefor any other type.
- get_citation(*, authors, year, title, link) str#
Write the citation in DataCite’s form: Creators (Year). Title. Publisher. Identifier.
Args: authors: The creators to name. year: The year of publication. title: The record’s title. link: Its DOI link, or the address of the page.
Returns: The citation as plain text.
- get_timeline(steps, dates, descriptions, entries) list[dict[str, Any]]#
Join the three ways the vocabularies describe a step in a record’s life.
A step combines a date type, a contributor role and a description type. Dated steps come first in date order, undated ones after them in the order given. A date recorded only to the year or the month is shown as recorded, never padded out to a day.
Args: steps:
[(date_type, role, description_type, label)], each type and role given by its address. dates: The record’s dates, keyed by the address of their type. descriptions: The record’s descriptions, keyed by the address of their type. entries: The record’s credits, from :meth:get_credits.Returns: One
{"label", "date", "day", "people", "note"}entry per step with anything to show.
- get_license_entry(licence, note=None) dict[str, Any]#
Write the Details card’s licence entry: the licence linked to its text, or a warning.
Args: licence: The licence, or
Nonewhen none is chosen. note: A line to show under the licence.Returns: An entry for :class:
c-card.details.
- get_composition_chart(samples, measurements) dict[str, Any] | None#
Draw the records by type, largest first, in one hue since the bars compare magnitude.
Args: samples: The samples to count. measurements: The measurements to count.
Returns: The chart, its height and its text alternative, or
Nonewhen there is nothing to count.
- get_growth_chart(samples, measurements) dict[str, Any] | None#
Draw the cumulative samples and measurements by month, two series on one count axis.
Args: samples: The samples to count. measurements: The measurements to count.
Returns: The chart and its text alternative, or
Nonewhen the records span fewer than two months.
- class TypedOverviewPlugin(**kwargs)#
Bases:
fairdm.core.plugins.RecordOverviewPluginThe overview of a record portals subclass: a sample or a measurement.
Two things differ from a project or dataset overview.
The template follows the record’s type. For each concrete class from the record’s own type up to
base_model, it looks for<app_label>/<model_name>_overview.html, then falls back tofallback_template. A type gets its own page by providing that template, extending its record’s template and filling theoverview.*blocks it wants. A subtype inherits its parent type’s page until it provides its own.The record follows its dataset. It opens for everyone once its own dataset is public and published, and otherwise only for people who hold a level on the record, or on its dataset or that dataset’s project (
visible_to). Anyone else gets a 404, so the address never confirms the record exists.PrivateRecordNotFoundMixincan’t be reused here: it readsobj.visibility, which samples and measurements don’t have.Initialization
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
- base_model#
None
- fallback_template#
None
- static check(request, obj)#
- handle_no_permission()#
Answer a viewer who may not open the record exactly as for a record that does not exist.
- get_template_names()#
Offer the record’s own type templates, most specific first, then the fallback.
- get_type_info() dict[str, Any] | None#
Read what the registry says about the record’s type and by whose rules it is recorded.
Returns: The description, the maintaining authority, the protocol citation and the keywords, or
Nonewhen the registry holds nothing to say.