fairdm.core.dataset.models#
Models for datasets and their related descriptions, dates, identifiers and literature links.
Module Contents#
Classes#
Link between a dataset and a literature item, typed with a DataCite relation type. |
|
QuerySet for datasets, with helpers that load related records in a bounded number of queries. |
|
The default manager for |
|
The unit a portal cites and distributes, optionally within a project. |
|
Typed prose about a dataset, at most one description per type. |
|
Typed dates marking points in a dataset’s life, at most one date per type. |
|
Typed external identifier naming a dataset outside the portal, at most one per type. |
Functions#
Return the pk of the portal’s configured default licence. |
Data#
API#
- get_default_license_pk()#
Return the pk of the portal’s configured default licence.
Reads
settings.FAIRDM_DEFAULT_LICENSEat call time, not at import time, sooverride_settingsand per-portal configuration are both honoured. Falls back to “CC BY 4.0” where a portal states none.Returns: The licence pk, or
Nonewhen the portal has not seeded its licences yet.
- DATACITE_RELATIONSHIP_TYPES#
[(‘IsCitedBy’,), (‘Cites’,), (‘IsSupplementTo’,), (‘IsSupplementedBy’,), (‘IsContinuedBy’,), (‘Conti…
- class DatasetLiteratureRelation(*args, **kwargs)#
Bases:
fairdm.db.models.ModelLink between a dataset and a literature item, typed with a DataCite relation type.
Initialization
- dataset#
‘ForeignKey(…)’
- literature_item#
‘ForeignKey(…)’
- relationship_type#
‘CharField(…)’
- class DatasetQuerySet(model=None, query=None, using=None, hints=None)#
Bases:
fairdm.core.managers.RecordLevelMixin,fairdm.db.models.QuerySetQuerySet for datasets, with helpers that load related records in a bounded number of queries.
None of the methods widens an already-narrowed query.
Dataset.objectsexcludes private datasets before a caller holds a queryset, soDataset.all_objectsis the route to every dataset.Initialization
- get_visible() fairdm.core.dataset.models.DatasetQuerySet#
Return the public datasets that are not inside a private project.
A private project hides everything beneath it, so a public dataset in one is left out. A dataset with no project counts on its own visibility.
Returns: The datasets a profile or a public listing may name.
- published() fairdm.core.dataset.models.DatasetQuerySet#
Return the datasets whose
publishedflag is set.Call it on
all_objects, notobjects: the default manager excludes private datasets, and a published private dataset is an ordinary state a related-record filter must still offer.Returns: The published datasets.
Prefetch the project and contributors.
Returns: The queryset with the prefetches applied.
- with_contributors() fairdm.core.dataset.models.DatasetQuerySet#
Prefetch only the contributors, which is lighter than
with_related().Returns: The queryset with the prefetch applied.
- with_list_data() fairdm.core.dataset.models.DatasetQuerySet#
Load everything a dataset card draws, and annotate its sample and measurement counts.
The counts are not filtered: a sample or measurement is as visible as its dataset, and this queryset is already narrowed to the datasets the visitor may see.
Returns: The queryset with the related records and counts loaded.
- with_metadata() fairdm.core.dataset.models.DatasetQuerySet#
Prefetch descriptions, dates, identifiers, contributions and keywords.
Returns: The queryset with the prefetches applied.
- class DatasetManager#
Bases:
models.Manager.from_queryset(DatasetQuerySet)The default manager for
Dataset, which excludes private datasets.Built from
DatasetQuerySetso the queryset helpers work on the default manager too. Forward relations and the deletion collector use the unfiltered base manager, so following a relation to a private dataset, or cascading a deletion to one, is unaffected.- get_queryset() fairdm.core.dataset.models.DatasetQuerySet#
Exclude private datasets.
- class Dataset(*args, **kwargs)#
Bases:
fairdm.core.abstract.BaseModelThe unit a portal cites and distributes, optionally within a project.
Samples and measurements hang beneath a dataset, and
has_datareports whether any do. A dataset is private until its visibility is set otherwise:objectsexcludes private datasets andall_objectsreturns every dataset. Deleting its project deletes it too. A dataset created with no licence gets the portal’s default (get_default_license_pk).Related records are
DatasetDescription,DatasetDate,DatasetIdentifierandDatasetLiteratureRelation, pluscontributors, whose roles come fromCONTRIBUTOR_ROLES.Initialization
- CONTRIBUTOR_ROLES#
None
- DATE_TYPES#
None
- DESCRIPTION_TYPES#
None
- IDENTIFIER_TYPES#
None
- VISIBILITY_CHOICES#
None
- DEFAULT_ROLES#
None
- objects#
‘DatasetManager(…)’
- all_objects#
‘as_manager(…)’
- uuid#
‘ShortUUIDField(…)’
- visibility#
‘IntegerField(…)’
- published#
‘BooleanField(…)’
- contributors#
‘GenericRelation(…)’
- created_by#
‘ForeignKey(…)’
- project#
‘ForeignKey(…)’
- reference#
‘OneToOneField(…)’
‘ManyToManyField(…)’
- license#
‘LicenseField(…)’
- class Meta#
- verbose_name#
‘_(…)’
- verbose_name_plural#
‘_(…)’
‘datasets’
- ordering#
[‘-modified’]
- indexes#
None
- permissions#
None
- property data_is_public: bool#
Whether anyone may see this dataset’s samples and measurements.
Publishing is meant to make a dataset public, so a published dataset should never be private. The two fields are still set separately, so both are checked.
- clean()#
Refuse a change of project that would leave the dataset with nobody to manage it.
- get_absolute_url()#
Return the URL of the dataset’s registered overview page.
- has_data()#
Return whether the dataset holds any samples or measurements, in a single query.
Returns: True when at least one sample or measurement hangs beneath the dataset.
- spatial_coverage(user=None)#
Return the smallest box holding the locations of the dataset’s records the viewer may see.
Samples count by their own location and measurements by their effective location for the viewer, so a measurement placed only by a sample the viewer may not open adds nothing.
Args: user: The viewer, or
Nonefor a visitor who is not signed in.Returns: A
Coveragein WGS 84 degrees, withwestgreater thaneastwhen it crosses the 180th meridian, orNonewhen nothing the viewer may see is located.
- class DatasetDescription(*args, **kwargs)#
Bases:
fairdm.core.abstract.AbstractDescriptionTyped prose about a dataset, at most one description per type.
Enforced by
clean()and by a database constraint.Initialization
- type#
‘ConceptField(…)’
‘ForeignKey(…)’
- class Meta#
Bases:
fairdm.core.abstract.AbstractDescription.Meta- indexes#
None
- clean()#
Refuse a second description of a type the dataset already carries.
- class DatasetDate(*args, **kwargs)#
Bases:
fairdm.core.abstract.AbstractDateTyped dates marking points in a dataset’s life, at most one date per type.
Enforced by
clean()and by a database constraint. The collection end cannot precede the collection start.Initialization
- type#
‘ConceptField(…)’
‘ForeignKey(…)’
- START_TYPE#
None
- END_TYPE#
None
- class Meta#
Bases:
fairdm.core.abstract.AbstractDate.Meta- indexes#
None
- clean()#
Refuse a collection end date that precedes the collection start date.
- class DatasetIdentifier(*args, **kwargs)#
Bases:
fairdm.core.abstract.AbstractIdentifierTyped external identifier naming a dataset outside the portal, at most one per type.
Enforced by a database constraint. The same value cannot name two records: the cross-record check lives in
AbstractIdentifier.clean().Initialization
- type#
‘ConceptField(…)’
‘ForeignKey(…)’