fairdm.core.abstract#
Abstract base models shared by the core records and their related rows.
Module Contents#
Classes#
Abstract base for the core records, adding an image, name, keywords, tags and options. |
|
Abstract base for the polymorphic core records (samples and measurements). |
|
QuerySet for GenericModel subclasses that provides vocabulary-based ordering. |
|
Manager for GenericModel subclasses. |
|
Abstract base for the typed rows attached to a record, such as descriptions and dates. |
|
Abstract base for a typed free-text description of a record. |
|
Abstract base for a typed partial date on a record. |
|
An external identifier attached to a record. |
Data#
API#
- class BaseModel(*args, **kwargs)#
Bases:
fairdm.db.models.ModelAbstract base for the core records, adding an image, name, keywords, tags and options.
Initialization
- image#
‘ThumbnailerImageField(…)’
- name#
‘CharField(…)’
- keywords#
‘MultiConceptField(…)’
- tags#
‘TaggableManager(…)’
- options#
‘JSONField(…)’
- tracker#
‘FieldTracker(…)’
- property icon#
Return the icon name for the model.
- property title#
Return the record’s name as its title.
- get_non_polymorphic_instance()#
Return the non-polymorphic version of this instance, or the instance itself if it is not polymorphic.
Returns: The non-polymorphic instance.
- get_absolute_url()#
Return the URL of the record’s detail page.
- get_api_url()#
Return the URL of the record’s API detail endpoint.
- add_contributor(contributor, with_roles=None)#
Credit a contributor on this object under the given roles.
A contributor holds one credit per object, carrying every role they have on it, so crediting the same contributor again adds the new roles to the credit already recorded rather than starting a second one. This matches
Contributor.add_toandContribution.add_to, the other two ways to record a credit.A person credited here for the first time starts at the view level, as one added from the Contributors tab does. An organization holds no level.
Args: contributor: The contributor to credit. with_roles: Addresses of the contributor role concepts to add to the credit.
Returns: The contributor’s credit on this object.
- is_contributor(user)#
Return whether the user is credited as a contributor.
Args: user: The user to look for.
Returns: True when the user has a credit on this object.
- get_direct_contributors()#
Return the people and organizations directly listed as contributors.
Returns: A queryset of contributors with a credit on this object.
- get_affiliated_organizations()#
Return the organizations that appear as affiliations in person contributions.
Returns: A queryset of organizations.
- get_all_contributors()#
Return every direct contributor together with the organizations they are affiliated with.
Returns: A queryset of contributors.
- get_abstract()#
Return the Abstract description, or
None.Returns: The description of the abstract type, if the record has one.
- get_abstract_summary()#
Return the abstract as a bounded run of plain text, or
"".AbstractDescription.valueis markdown, so a template that prints it directly shows the reader##and**. This renders it through the portal’s sanitising renderer, drops the tags, collapses whitespace and caps the result at 400 characters so one long abstract cannot set the height of a card.Returns: Plain text, not markup. The template layer escapes it like any other string, so never mark it safe.
- get_meta_description()#
Return the Abstract’s full text for the page meta description, or
None.Unlike
get_abstract_summary(), the text is not truncated (#331).Returns: The abstract’s value, if the record has an abstract.
- get_descriptions()#
Return the record’s descriptions as a list, cached on first access.
Returns: The list of descriptions.
- verbose_name()#
Return the model’s singular verbose name.
Returns: The verbose name from the model options.
- verbose_name_plural()#
Return the model’s plural verbose name.
Returns: The plural verbose name from the model options.
- class BasePolymorphicModel(*args, **kwargs)#
Bases:
fairdm.db.models.PolymorphicModel,fairdm.core.abstract.BaseModelAbstract base for the polymorphic core records (samples and measurements).
Initialization
- classmethod get_inheritance_chain()#
Return the chain of classes from the concrete model up to its polymorphic base.
Returns: The classes in the inheritance chain.
- get_absolute_url()#
Return the URL of the record’s overview page.
- class GenericModelQuerySet(model=None, query=None, using=None, hints=None)#
Bases:
django.db.models.QuerySetQuerySet for GenericModel subclasses that provides vocabulary-based ordering.
Initialization
- in_order()#
Order the rows by the order of the collection their
typefield offers.Rows whose type is not in the collection sort to the end.
Returns: A list of instances in the collection’s order.
Example: # Get dataset descriptions in vocabulary order dataset.descriptions.in_order()
# Chain with other queryset methods dataset.descriptions.filter(type__in=[ABSTRACT, METHODS]).in_order()
- class GenericModelManager#
Bases:
django.db.models.ManagerManager for GenericModel subclasses.
- get_queryset()#
Return a
GenericModelQuerySet.
- in_order()#
Return every object in the order of the collection its
typefield offers.Returns: A list of instances in the collection’s order.
- class GenericModel(*args, **kwargs)#
Bases:
django.db.models.ModelAbstract base for the typed rows attached to a record, such as descriptions and dates.
Each concrete subclass declares
typeas aConceptFieldrestricted to the collection of the vocabulary that its kind of record uses.Initialization
- modified#
None
- added#
None
- objects#
‘GenericModelManager(…)’
- classmethod get_type_concepts()#
Return the concepts the
typefield offers, in its collection’s order.Returns: A list of
controlled_vocabularies.Recordconcepts.
- get_update_url()#
Return the URL of the page that edits this row.
- verbose_name()#
Return the model’s singular verbose name.
Returns: The verbose name from the model options.
- verbose_name_plural()#
Return the model’s plural verbose name.
Returns: The plural verbose name from the model options.
- DESCRIPTION_MAX_LENGTH#
20000
- class AbstractDescription(*args, **kwargs)#
Bases:
fairdm.core.abstract.GenericModelAbstract base for a typed free-text description of a record.
Initialization
- value#
‘TextField(…)’
- class AbstractDate(*args, **kwargs)#
Bases:
fairdm.core.abstract.GenericModelAbstract base for a typed partial date on a record.
Initialization
- value#
‘PartialDateField(…)’
- class AbstractIdentifier(*args, **kwargs)#
Bases:
fairdm.core.abstract.GenericModelAn external identifier attached to a record.
valuecarriesunique=True, which is a per-table constraint: since this model is abstract, each concrete subclass (dataset, project, sample, measurement) gets its own index, so the same value could otherwise name two different kinds of record at once.clean()closes that gap by checking the value against every concrete subclass, not only the one being validated.Initialization
- value#
‘CharField(…)’
- class Meta#
- abstract#
True
- verbose_name#
‘_(…)’
- verbose_name_plural#
‘_(…)’
‘identifiers’
- constraints#
None
- clean()#
Reject an identifier value already used by any identifier model.
- get_root_url()#
Return the base URL of the identifier’s resolver.
Returns: The resolver URL registered for the identifier’s type, or None when it has none.
- get_absolute_url()#
Return the URL of the identifier’s resolver page.
Returns: The address the identifier resolves to, or None for a type with no resolver.