fairdm.contrib.contributors.managers#

Managers and querysets for people, affiliations and contributions.

Module Contents#

Classes#

OrganizationQuerySet

Organization queryset with the lookups that find organizations by where they are.

PersonQuerySet

Person queryset with a filter for each claim and account state.

UserManager

Manager for the Person model, which has no username field.

AffiliationQuerySet

Affiliation queryset with filters for primary, current, past and owner affiliations.

AffiliationManager

Manager for the Affiliation model, exposing the AffiliationQuerySet filters.

ContributionQuerySet

Contribution queryset with filters by role, entity and contributor.

ContributionManager

Manager for the Contribution model, with the ordered-model methods and the ContributionQuerySet filters.

API#

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

Bases: fairdm.utils.location.managers.LocatedQuerySet, fairdm.db.models.PrefetchPolymorphicQuerySet

Organization queryset with the lookups that find organizations by where they are.

Initialization

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

Bases: fairdm.db.models.PrefetchPolymorphicQuerySet

Person queryset with a filter for each claim and account state.

Initialization

real()#

Exclude superusers and the django-guardian anonymous user.

Returns: Persons that are not superusers and do not have the email AnonymousUser.

active()#

Filter to active persons.

Returns: Persons with is_active true.

inactive()#

Filter to deactivated accounts, whatever their claim status or email.

Returns: Persons with is_active false.

claimed()#

Filter to active persons who have claimed their accounts.

A deactivated account is never claimed here, even though its flag is still true.

Returns: Persons with is_active and is_claimed true.

unclaimed()#

Filter to persons who have not claimed their accounts.

This covers both ghost profiles and invited profiles.

Returns: Persons with is_claimed false.

ghost()#

Filter to ghost profiles, the attribution-only records made by create_unclaimed.

Returns: Active, unclaimed persons with no email.

invited()#

Filter to invited profiles, which have an email but have not been claimed.

Returns: Active, unclaimed persons with an email.

for_cards()#

Prefetch everything a person’s card reads, so a listing costs no query per person.

The card reads the person’s identifiers, sign-in accounts, affiliations with their organisations, and portal roles.

Returns: The queryset with those relations prefetched.

class UserManager#

Bases: django.contrib.auth.models.BaseUserManager, PrefetchPolymorphicManager.from_queryset(PersonQuerySet)

Manager for the Person model, which has no username field.

The state filters come from PersonQuerySet.

use_in_migrations#

False

create_user(email, password=None, **extra_fields)#

Create and save a non-staff person with the given email and password.

Args: email: The person’s email. password: The password. None sets an unusable password. **extra_fields: Other model fields.

Returns: The saved person.

create_superuser(email, password=None, **extra_fields)#

Create and save a staff superuser with the given email and password.

Args: email: The user’s email. password: The password. None sets an unusable password. **extra_fields: Other model fields.

Returns: The saved superuser.

Raises: ValueError: is_staff or is_superuser is passed as false.

create_unclaimed(first_name: str, last_name: str, **extra_fields)#

Create a ghost profile: an active, unclaimed person with no email and an unusable password.

Args: first_name: Given name. last_name: Family name. **extra_fields: Any other Contributor or Person fields.

Returns: The saved person.

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

Bases: django.db.models.QuerySet

Affiliation queryset with filters for primary, current, past and owner affiliations.

Initialization

primary()#

Return the affiliation marked primary.

Returns: The primary affiliation, or None when none is set.

current()#

Filter to current affiliations, which have no end date.

Returns: Affiliations with end_date null.

past()#

Filter to past affiliations, which have an end date.

Returns: Affiliations with end_date set.

owners()#

Filter to current owner affiliations.

Ownership is defined here once: a current affiliation (see :meth:current) of type OWNER. An ended OWNER affiliation confers no ownership.

Returns: Current affiliations with type OWNER.

class AffiliationManager#

Bases: models.Manager.from_queryset(AffiliationQuerySet)

Manager for the Affiliation model, exposing the AffiliationQuerySet filters.

primary() returns one affiliation or None, so it cannot be chained further.

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

Bases: ordered_model.models.OrderedModelQuerySet

Contribution queryset with filters by role, entity and contributor.

Initialization

by_role(role: str)#

Filter contributions to those holding a role.

Args: role: The address of a concept in the contributor roles vocabulary.

Returns: Contributions with that role.

for_entity(obj)#

Filter contributions to those credited on one object.

Args: obj: A model instance, such as a project or dataset, that contributions point at.

Returns: Contributions for that object.

by_contributor(contributor)#

Filter contributions to those by one contributor across all objects.

Args: contributor: The contributor.

Returns: Contributions by that contributor.

people()#

Filter contributions to those of people, in the order the record names them.

The kind is read from the contributor’s polymorphic content type, so no contributor is loaded.

Returns: Contributions whose contributor is a Person, ordered by order then pk.

organizations()#

Filter contributions to those of organizations, in the order the record names them.

The kind is read from the contributor’s polymorphic content type, so no contributor is loaded.

Returns: Contributions whose contributor is an Organization, ordered by order then pk.

class ContributionManager#

Bases: OrderedModelManager.from_queryset(ContributionQuerySet)

Manager for the Contribution model, with the ordered-model methods and the ContributionQuerySet filters.