fairdm.core.sample.models#
Models for samples and their related descriptions, dates, identifiers and relations.
Module Contents#
Classes#
A physical or digital object that is part of a dataset. |
|
Typed free-text description of a sample. |
|
Typed date on a sample. |
|
Typed external identifier of a sample, from the sample identifier collection (IGSN and DOI). |
|
Typed relationship between two samples, such as parent and child. |
Functions#
Refuse to save a bare |
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.BasePolymorphicModelA physical or digital object that is part of a dataset.
A polymorphic model: domain-specific sample types inherit from this base. The base
Sampleitself 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
sprefix. 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 throughSampleRelation. objects: The manager, with theSampleQuerySethelpers.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(…)’
‘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
SampleRelationobjects 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_ofrelation 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_ofrelation 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.
Noneis 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.
Noneis 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
Samplerow, by any route.Scoped to
sender=Samplebecause a subclass instance sends its own class, so this never fires for a registered sample type.pre_savealso 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
Samplecannot be saved.
- class SampleDescription(*args, **kwargs)#
Bases:
fairdm.core.abstract.AbstractDescriptionTyped free-text description of a sample.
Initialization
- type#
‘ConceptField(…)’
‘ForeignKey(…)’
- class SampleDate(*args, **kwargs)#
Bases:
fairdm.core.abstract.AbstractDateTyped date on a sample.
Initialization
- type#
‘ConceptField(…)’
‘ForeignKey(…)’
- class SampleIdentifier(*args, **kwargs)#
Bases:
fairdm.core.abstract.AbstractIdentifierTyped external identifier of a sample, from the sample identifier collection (IGSN and DOI).
Initialization
- type#
‘ConceptField(…)’
‘ForeignKey(…)’
- clean()#
Refuse an invalid IGSN.
- class SampleRelation(*args, **kwargs)#
Bases:
fairdm.db.models.ModelTyped 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_togetherconstraint 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.