fairdm.core.sample.models#

Models for samples and their related descriptions, dates, identifiers and relations.

Module Contents#

Classes#

Sample

A physical or digital object that is part of a dataset.

SampleDescription

Typed free-text description of a sample.

SampleDate

Typed date on a sample.

SampleIdentifier

Typed external identifier of a sample, from the sample identifier collection (IGSN and DOI).

SampleRelation

Typed relationship between two samples, such as parent and child.

Functions#

block_base_sample_creation

Refuse to save a bare Sample row, by any route.

Data#

API#

BASE_SAMPLE_ERROR#

‘_(…)’

IGSN_DISPLAY_PREFIXES#

(‘https://doi.org/’, ‘http://doi.org/’, ‘https://igsn.org/’, ‘hdl.handle.net/’, ‘doi:’, ‘igsn:’)

IGSN_DOI_PATTERN#

‘compile(…)’

IGSN_LEGACY_HANDLE_PATTERN#

‘compile(…)’

class Sample(*args, **kwargs)#

Bases: fairdm.core.abstract.BasePolymorphicModel

A physical or digital object that is part of a dataset.

A polymorphic model: domain-specific sample types inherit from this base. The base Sample itself cannot be saved.

Attributes: CONTRIBUTOR_ROLES: The roles a contributor can hold on a sample. DATE_TYPES: The date types a sample can carry. DESCRIPTION_TYPES: The description types a sample can carry. dataset: The dataset this sample belongs to. uuid: Unique short identifier with an s prefix. local_id: The creator’s own identifier for the sample within its dataset. status: The sample’s custody status, such as available or destroyed. location: The point where the sample was taken, in WGS 84. location_elevation: Metres above mean sea level. location_uncertainty: Metres within which the true place lies. contributors: Generic relation to contributor records. related: Samples related through SampleRelation. objects: The manager, with the SampleQuerySet helpers.

Initialization

CONTRIBUTOR_ROLES#

None

DATE_TYPES#

None

DESCRIPTION_TYPES#

None

dataset#

‘ForeignKey(…)’

uuid#

‘ShortUUIDField(…)’

local_id#

‘CharField(…)’

status#

‘ConceptField(…)’

location#

‘PointField(…)’

location_elevation#

‘FloatField(…)’

location_uncertainty#

‘FloatField(…)’

contributors#

‘GenericRelation(…)’

related#

‘ManyToManyField(…)’

objects#

‘(…)’

class Meta#
verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

ordering#

[‘added’]

‘samples’

indexes#

None

constraints#

‘location_constraints(…)’

permissions#

None

clean()#

Refuse a bare Sample, and a change of dataset that leaves nobody to manage it.

get_absolute_url()#

Return the URL of the sample’s overview page.

get_all_relationships()#

Return every relation in which this sample is the source or the target.

Returns: A queryset of SampleRelation objects involving this sample.

Return every sample related to this sample, as source or target.

Args: relationship_type: Only follow relations of this type, such as "child_of".

Returns: A queryset of the related samples, excluding this one.

get_children()#

Return the samples that are children of this one.

Returns: A queryset of samples with a child_of relation whose target is this sample.

get_parents()#

Return the samples that are parents of this one.

Returns: A queryset of samples that are the target of a child_of relation whose source is this sample.

get_descendants(depth=None)#

Return the descendants of this sample, optionally to a depth limit.

Delegates to SampleQuerySet.get_descendants, the single traversal implementation.

Args: depth: The maximum depth to traverse. None is unlimited, 1 is direct children only, 2 includes grandchildren, and so on.

Returns: A queryset of the descendant samples within the depth limit.

get_ancestors(depth=None)#

Return the ancestors of this sample, optionally to a depth limit.

Delegates to SampleQuerySet.get_ancestors, the single traversal implementation.

Args: depth: The maximum depth to traverse. None is unlimited, 1 is direct parents only, 2 includes grandparents, and so on.

Returns: A queryset of the ancestor samples within the depth limit.

type_of()#

Return the base Sample class for polymorphic queries.

get_template_name()#

Return the card templates to try for this sample, in order of preference.

Returns: The template paths.

block_base_sample_creation(sender, instance, **kwargs)#

Refuse to save a bare Sample row, by any route.

Scoped to sender=Sample because a subclass instance sends its own class, so this never fires for a registered sample type. pre_save also covers fixture loading, and it cannot fire on the framework’s own read path, where django-polymorphic never saves base instances. Sample.clean() stays alongside so forms and the admin raise a validation error instead.

Args: sender: The model class being saved. instance: The instance being saved. **kwargs: Additional signal arguments.

Raises: ValidationError: Always, since a bare Sample cannot be saved.

class SampleDescription(*args, **kwargs)#

Bases: fairdm.core.abstract.AbstractDescription

Typed free-text description of a sample.

Initialization

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

class SampleDate(*args, **kwargs)#

Bases: fairdm.core.abstract.AbstractDate

Typed date on a sample.

Initialization

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

class SampleIdentifier(*args, **kwargs)#

Bases: fairdm.core.abstract.AbstractIdentifier

Typed external identifier of a sample, from the sample identifier collection (IGSN and DOI).

Initialization

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

clean()#

Refuse an invalid IGSN.

class SampleRelation(*args, **kwargs)#

Bases: fairdm.db.models.Model

Typed relationship between two samples, such as parent and child.

A sample cannot relate to itself, and A to B and B to A with the same type is refused. The unique_together constraint on source, target and type prevents duplicate links.

Attributes: RELATION_TYPES: The relationship types offered. type: The type of relationship, such as child_of. source: The sample initiating the relationship. target: The sample being related to. added: Unused, as the model records no creation time. modified: Unused, as the model records no modification time.

Initialization

RELATION_TYPES#

[(‘child_of’,)]

type#

‘CharField(…)’

source#

‘ForeignKey(…)’

target#

‘ForeignKey(…)’

added#

None

modified#

None

class Meta#
unique_together#

[(‘source’, ‘target’, ‘type’)]

verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

clean()#

Refuse a self-reference or a two-step loop.

save(*args, **kwargs)#

Refuse a self-reference or a two-step loop even when saved directly.