fairdm.core.dataset.models#

Models for datasets and their related descriptions, dates, identifiers and literature links.

Module Contents#

Classes#

DatasetLiteratureRelation

Link between a dataset and a literature item, typed with a DataCite relation type.

DatasetQuerySet

QuerySet for datasets, with helpers that load related records in a bounded number of queries.

DatasetManager

The default manager for Dataset, which excludes private datasets.

Dataset

The unit a portal cites and distributes, optionally within a project.

DatasetDescription

Typed prose about a dataset, at most one description per type.

DatasetDate

Typed dates marking points in a dataset’s life, at most one date per type.

DatasetIdentifier

Typed external identifier naming a dataset outside the portal, at most one per type.

Functions#

get_default_license_pk

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_LICENSE at call time, not at import time, so override_settings and per-portal configuration are both honoured. Falls back to “CC BY 4.0” where a portal states none.

Returns: The licence pk, or None when 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.Model

Link between a dataset and a literature item, typed with a DataCite relation type.

Initialization

dataset#

‘ForeignKey(…)’

literature_item#

‘ForeignKey(…)’

relationship_type#

‘CharField(…)’

class Meta#
verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

unique_together#

[[‘dataset’, ‘literature_item’, ‘relationship_type’]]

indexes#

None

class DatasetQuerySet(model=None, query=None, using=None, hints=None)#

Bases: fairdm.core.managers.RecordLevelMixin, fairdm.db.models.QuerySet

QuerySet for datasets, with helpers that load related records in a bounded number of queries.

None of the methods widens an already-narrowed query. Dataset.objects excludes private datasets before a caller holds a queryset, so Dataset.all_objects is 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 published flag is set.

Call it on all_objects, not objects: 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 DatasetQuerySet so 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.BaseModel

The unit a portal cites and distributes, optionally within a project.

Samples and measurements hang beneath a dataset, and has_data reports whether any do. A dataset is private until its visibility is set otherwise: objects excludes private datasets and all_objects returns 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, DatasetIdentifier and DatasetLiteratureRelation, plus contributors, whose roles come from CONTRIBUTOR_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(…)’

related_literature: fairdm.db.models.ManyToManyField#

‘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 None for a visitor who is not signed in.

Returns: A Coverage in WGS 84 degrees, with west greater than east when it crosses the 180th meridian, or None when nothing the viewer may see is located.

class DatasetDescription(*args, **kwargs)#

Bases: fairdm.core.abstract.AbstractDescription

Typed prose about a dataset, at most one description per type.

Enforced by clean() and by a database constraint.

Initialization

type#

‘ConceptField(…)’

related#

‘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.AbstractDate

Typed 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(…)’

related#

‘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.AbstractIdentifier

Typed 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(…)’

related#

‘ForeignKey(…)’