fairdm.core.project.models#

Models for projects and their related descriptions, dates and identifiers.

Module Contents#

Classes#

ProjectQuerySet

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

Project

A collection of datasets and associated metadata.

ProjectDescription

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

ProjectDate

Typed date on a project, at most one per type, with the end no earlier than the start.

ProjectIdentifier

Typed external identifier naming a project outside the portal.

Functions#

prevent_project_deletion_with_datasets

Block deleting a project that has public datasets.

API#

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

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

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

Initialization

get_visible() → fairdm.core.project.models.ProjectQuerySet#

Return only the projects with public visibility.

Returns: The public projects.

with_contributors() → fairdm.core.project.models.ProjectQuerySet#

Prefetch the contributions and the contributors behind them.

Callers go on to name the person or organisation behind each credit, and Contributor is polymorphic, so resolving them lazily costs two queries per credit.

Returns: The queryset with the prefetch applied.

with_metadata() → fairdm.core.project.models.ProjectQuerySet#

Load the owner, descriptions, dates, identifiers, contributions and keywords.

Returns: The queryset with the related records loaded.

with_list_data() → fairdm.core.project.models.ProjectQuerySet#

Load everything a project card draws, and annotate dataset_count.

The count covers public datasets only. An annotation aggregates over a join and never consults a manager, so the exclusion of private datasets is written into the aggregate.

Returns: The queryset with the related records and count loaded.

class Project(*args, **kwargs)#

Bases: fairdm.core.abstract.BaseModel

A collection of datasets and associated metadata.

The top-level model in the FairDM schema hierarchy: datasets, samples and measurements should relate back to a project.

Initialization

DEFAULT_ROLES#

None

CONTRIBUTOR_ROLES#

None

DATE_TYPES#

None

DESCRIPTION_TYPES#

None

STATUS_CHOICES#

None

VISIBILITY#

None

objects#

‘as_manager(…)’

uuid#

‘ShortUUIDField(…)’

visibility#

‘IntegerField(…)’

funding#

‘JSONField(…)’

status#

‘IntegerField(…)’

contributors#

‘GenericRelation(…)’

created_by#

‘ForeignKey(…)’

owner#

‘ForeignKey(…)’

STATUS_BADGE_VARIANTS#

None

property is_active#

Whether work on the project is under way: its status is in progress.

property status_badge_variant#

Return the theme colour name for this project’s status badge.

Falls back to neutral so a status without an entry above still renders a legible badge.

spatial_coverage(user=None)#

Return the smallest box holding the locations of the project’s datasets the viewer may open.

The datasets are the public ones and those the viewer holds a level on. Within them, the records counted are the ones the viewer may see, as :meth:Dataset.spatial_coverage counts them.

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.

get_absolute_url()#

Return the URL of the project’s registered overview page.

class Meta#
verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

‘projects’

ordering#

[‘-modified’]

indexes#

None

permissions#

None

class ProjectDescription(*args, **kwargs)#

Bases: fairdm.core.abstract.AbstractDescription

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

Initialization

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

class Meta#

Bases: fairdm.core.abstract.AbstractDescription.Meta

unique_together#

[(‘related’, ‘type’)]

verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

clean()#

Refuse a second description of a type the project already carries.

class ProjectDate(*args, **kwargs)#

Bases: fairdm.core.abstract.AbstractDate

Typed date on a project, at most one per type, with the end no earlier than the start.

Initialization

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

START_TYPE#

None

END_TYPE#

None

class Meta#

Bases: fairdm.core.abstract.AbstractDate.Meta

verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

clean()#

Refuse an end date that precedes the start date.

class ProjectIdentifier(*args, **kwargs)#

Bases: fairdm.core.abstract.AbstractIdentifier

Typed external identifier naming a project outside the portal.

Initialization

type#

‘ConceptField(…)’

related#

‘ForeignKey(…)’

class Meta#

Bases: fairdm.core.abstract.AbstractIdentifier.Meta

verbose_name#

‘_(…)’

verbose_name_plural#

‘_(…)’

exception PublicDatasetsProtect(datasets)#

Bases: Exception

Raised before a project is deleted while it still has public datasets.

Args: datasets: The queryset of public datasets blocking deletion.

Initialization

Initialize self. See help(type(self)) for accurate signature.

prevent_project_deletion_with_datasets(sender, instance, **kwargs)#

Block deleting a project that has public datasets.

A project with only private datasets can be deleted, and they go with it by cascade.

Args: sender: The Project model class. instance: The project being deleted. **kwargs: Additional signal arguments.

Raises: PublicDatasetsProtect: The project has public datasets.