fairdm.core.managers#
Polymorphic manager and the record-visibility queryset mixin shared by the core record types.
Module Contents#
Classes#
Polymorphic manager that can count records per child type. |
|
The |
|
QuerySet methods for records that follow their own dataset: samples and measurements. |
API#
- class PolymorphicManager#
Bases:
polymorphic.managers.PolymorphicManagerPolymorphic manager that can count records per child type.
- get_type_counts()#
Count the records of each polymorphic child type.
Returns: A dictionary mapping each child model class to the number of records of that type.
- class RecordLevelMixin#
The
with_levelqueryset method, shared by projects, datasets, samples and measurements.A record is held on its own contributions and on those of the records above it: a dataset on its project, a sample or measurement on its dataset and that dataset’s project. A measurement follows its own dataset, not its sample’s.
- with_level(user, level)#
Return the records the user holds at least a level on.
Args: user: The user, or
Noneor an anonymous user for a visitor. level: The least level wanted, aContributionLevel.Returns: The records the user holds the level on, on the record itself or from a record above. None for a visitor or an inactive user.
- accessible_to(user, level)#
Return the records the user holds a level on, and every record for a portal-wide right.
Choice lists and filters offer the same records the permission backends would let the user act on: those the user holds the level on, and all of them for someone the portal gives
view(for the view level) orchange(for edit and manage) on the whole model, as a superuser or a Data Curator has.Args: user: The user, or
Noneor an anonymous user for a visitor. level: The least level wanted, aContributionLevel.Returns: The records the user may act on at that level.
- class RecordVisibilityMixin#
Bases:
fairdm.core.managers.RecordLevelMixinQuerySet methods for records that follow their own dataset: samples and measurements.
Both rules are applied per record, against the record’s own dataset. Being on one dataset’s team never opens another dataset’s records. The queryset it is mixed into must have a
datasetforeign key.- published()#
Return the records whose own dataset is published.
It is a bare filter with no
select_related, as it also builds filter choice lists. Deliberatelydataset__published: a record’s presence is decided by the dataset that owns it, not by the dataset that owns a record it hangs from.Returns: The records in published datasets.
- visible_to(user)#
Return the records the user may see.
Those whose own dataset is public and published, and those the user holds a level on, on the record itself or from its dataset or that dataset’s project. Someone listed only on one record sees that record and not its siblings. A user who holds
view_datasetorchange_datasetfor the whole portal sees every record.Args: user: The user, or
Nonefor a visitor.Returns: The records the user may see.