Models
We have four main abstractions: Users, Collections, Memberships, and Roles.
Users represent people, like students in a school, teachers for a classroom, or volunteers setting up informal
installations. A FacilityUser belongs to a particular facility, and has permissions only with respect to other data
that is associated with that facility. FacilityUser accounts (like other facility data) may be synced across multiple
devices.
Collections form a hierarchy, with Collections able to belong to other Collections. Collections are subdivided
into several pre-defined levels (Facility > Classroom > LearnerGroup).
A FacilityUser can be marked as a member of a Collection through a Membership
object. Being a member of a Collection also means being a member of all the Collections above that Collection in the
hierarchy.
Another way in which a FacilityUser can be associated with a particular Collection is through a Role
object, which grants the user a role with respect to the Collection and all the collections below it. A Role
object also stores the “kind” of the role (currently, one of “admin” or “coach”), which affects what permissions the
user gains through the Role.
- class kolibri.core.auth.models.AbstractFacilityDataModel(*args, **kwargs)[source]
Base model for Kolibri “Facility Data”, which is data that is specific to a particular
Facility, such asFacilityUsers,Collections, and other data associated with those users and collections.- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Dataset
- cached_related_dataset_lookup(related_obj_name)[source]
Attempt to get the dataset_id either from the cache or the actual related obj instance.
- Parameters:
related_obj_name – string representing the name of the related object on this model
- Returns:
the dataset_id associated with the related obj
- calculate_source_id()[source]
Should return a string that uniquely defines the model instance or None for a random uuid.
- clean_fields(exclude=None, sync_filter=None)[source]
Immediately validates all fields
- Parameters:
exclude (list[str]) – A list of field names to exclude from validation
sync_filter (Filter|None) – The current sync’s filter, if any
- ensure_dataset(*args, **kwargs)[source]
If no dataset has yet been specified, try to infer it. If a dataset has already been specified, to prevent inconsistencies, make sure it matches the inferred dataset, otherwise raise a
KolibriValidationError. If we have no dataset and it can’t be inferred, we raise aKolibriValidationErrorexception as well.
- full_clean(*args, **kwargs)[source]
Call clean_fields(), clean(), and validate_unique() on the model. Raise a ValidationError for any errors that occur.
- infer_dataset(*args, **kwargs)[source]
This method is used by ensure_dataset to “infer” which dataset should be associated with this instance. It should be overridden in any subclass of
AbstractFacilityDataModel, to define a model-specific inference.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.AdHocGroup(*args, **kwargs)[source]
An
AdHocGroupis a collection kind that can be used in an assignment to create a group that is specific to a singleLesson,ExamorCourseSession.- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetname (CharField) – Name
parent_id (ForeignKey to
~) – Parentkind (CharField) – Kind
- exception DoesNotExist
- exception MultipleObjectsReturned
- classmethod deserialize(dict_model, sync_filter=None)[source]
Returns an unsaved class object based on the valid properties passed in.
- Parameters:
dict_model (dict) – The model data to deserialize
sync_filter (Filter|None) – The current sync’s filter, if any
- get_classroom()[source]
Gets the
AdHocGroup’s parentClassroom.- Returns:
A
Classroominstance.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.Classroom(id, _morango_dirty_bit, _morango_source_id, _morango_partition, dataset, name, parent, kind)[source]
- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetname (CharField) – Name
parent_id (ForeignKey to
~) – Parentkind (CharField) – Kind
- exception DoesNotExist
- exception MultipleObjectsReturned
- get_facility()[source]
Gets the
Classroom’s parentFacility.- Returns:
A
Facilityinstance.
- get_individual_learners_group()[source]
Returns a
QuerySetofAdHocGroups.:return A
AdHocGroupQuerySet.
- get_learner_groups()[source]
Returns a
QuerySetofLearnerGroupsassociated with thisClassroom.- Returns:
A
LearnerGroupQuerySet.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.Collection(*args, **kwargs)[source]
Collectionsare hierarchical groups ofFacilityUsers, used for grouping users and making decisions about permissions.FacilityUserscan have roles for one or moreCollections, by way of obtainingRolesassociated with thoseCollections.Collectionscan belong to otherCollections, and user membership in aCollectionis conferred throughMemberships.Collectionsare subdivided into several pre-defined levels.- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetname (CharField) – Name
parent_id (ForeignKey to
~) – Parentkind (CharField) – Kind
- exception DoesNotExist
- exception MultipleObjectsReturned
- add_member(user)[source]
Create a
Membershipassociating the provided user with thisCollection. If theMembershipobject already exists, just return that, without changing anything.- Parameters:
user – The
FacilityUserto add to thisCollection.- Returns:
The
Membershipobject (possibly new) that associates the user with theCollection.
- add_role(user, role_kind)[source]
Create a
Roleassociating the provided user with this collection, with the specified kind of role. If the Role object already exists, just return that, without changing anything.- Parameters:
user – The
FacilityUserto associate with thisCollection.role_kind – The kind of role to give the user with respect to this
Collection.
- Returns:
The
Roleobject (possibly new) that associates the user with theCollection.
- calculate_partition()[source]
Should return a string specifying this model instance’s partition, using self.ID_PLACEHOLDER in place of its own ID, if needed.
- clean_fields(exclude=None, sync_filter=None)[source]
Immediately validates all fields
- Parameters:
exclude (list[str]) – A list of field names to exclude from validation
sync_filter (Filter|None) – The current sync’s filter, if any
- get_admins()[source]
Returns users who have the admin role for this immediate collection.
- get_coaches()[source]
Returns users who have the coach role for this immediate collection.
- infer_dataset(*args, **kwargs)[source]
This method is used by ensure_dataset to “infer” which dataset should be associated with this instance. It should be overridden in any subclass of
AbstractFacilityDataModel, to define a model-specific inference.
- remove_member(user)[source]
Remove any
Membershipobjects associating the provided user with thisCollection.- Parameters:
user – The
FacilityUserto remove from thisCollection.- Returns:
Trueif aMembershipwas removed,Falseif there was no matchingMembershipto remove.
- remove_role(user, role_kind)[source]
Remove any
Roleobjects associating the provided user with thisCollection, with the specified kind of role.- Parameters:
user – The
FacilityUserto dissociate from thisCollection(for the specific role kind).role_kind – The kind of role to remove from the user with respect to this
Collection.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.DatasetCache[source]
- class kolibri.core.auth.models.Facility(id, _morango_dirty_bit, _morango_source_id, _morango_partition, dataset, name, parent, kind)[source]
- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetname (CharField) – Name
parent_id (ForeignKey to
~) – Parentkind (CharField) – Kind
- exception DoesNotExist
- exception MultipleObjectsReturned
- ensure_dataset(*args, **kwargs)[source]
If no dataset has yet been specified, try to infer it. If a dataset has already been specified, to prevent inconsistencies, make sure it matches the inferred dataset, otherwise raise a
KolibriValidationError. If we have no dataset and it can’t be inferred, we raise aKolibriValidationErrorexception as well.
- get_classrooms()[source]
Returns a QuerySet of Classrooms under this Facility.
- Returns:
A Classroom QuerySet.
- infer_dataset(*args, **kwargs)[source]
This method is used by ensure_dataset to “infer” which dataset should be associated with this instance. It should be overridden in any subclass of
AbstractFacilityDataModel, to define a model-specific inference.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.FacilityDataSyncableModel(*args, **kwargs)[source]
- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
- class kolibri.core.auth.models.FacilityDataset(*args, **kwargs)[source]
FacilityDatasetstores high-level metadata and settings for a particularFacility. It is also the model that all models storing facility data (data that is associated with a particular facility, and that inherits fromAbstractFacilityDataModel) foreign key onto, to indicate that they belong to this particularFacility.- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
description (TextField) – Description
location (CharField) – Location
preset (CharField) – Preset
learner_can_edit_username (BooleanField) – Learner can edit username
learner_can_edit_name (BooleanField) – Learner can edit name
learner_can_edit_password (BooleanField) – Learner can edit password
learner_can_sign_up (BooleanField) – Learner can sign up
learner_can_delete_account (BooleanField) – Learner can delete account
learner_can_login_with_no_password (BooleanField) – Learner can login with no password
show_download_button_in_learn (BooleanField) – Show download button in learn
enable_mark_attendance (BooleanField) – Enable mark attendance
picture_password_settings (JSONField) – Picture password settings
extra_fields (JSONField) – Extra fields
registered (BooleanField) – Registered
- exception DoesNotExist
- exception MultipleObjectsReturned
- calculate_partition()[source]
Should return a string specifying this model instance’s partition, using self.ID_PLACEHOLDER in place of its own ID, if needed.
- calculate_source_id()[source]
Should return a string that uniquely defines the model instance or None for a random uuid.
- full_facility_import
Returns True if this user is a member of a facility that has been fully imported.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- validate_demographic_data(demographic_data)[source]
Use the custom schema to validate demographic data being set on a FacilityUser.
- class kolibri.core.auth.models.FacilityUser(*args, **kwargs)[source]
FacilityUseris the fundamental object of the auth app. These users represent the main users, and can be associated with a hierarchy ofCollectionsthroughMembershipsandRoles, which then serve to help determine permissions.- Parameters:
password (CharField) – Password
last_login (DateTimeField) – Last login
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetusername (CharField) – Required. 254 characters or fewer.
full_name (CharField) – Full name
date_joined (DateTimeTzField) – Date joined
facility_id (ForeignKey to
~) – Facilitygender (CharField) – Gender
birth_year (CharField) – Birth year
id_number (CharField) – Id number
extra_demographics (JSONField) – Extra demographics
date_deleted (DateTimeTzField) – Date deleted
picture_password (CharField) – Picture password
- exception DoesNotExist
- exception MultipleObjectsReturned
- calculate_partition()[source]
Should return a string specifying this model instance’s partition, using self.ID_PLACEHOLDER in place of its own ID, if needed.
- can_create_instance(obj)[source]
Checks whether this user (self) has permission to create a particular model instance (obj).
This method should be overridden by classes that inherit from
KolibriBaseUserMixin.In general, unless an instance has already been initialized, this method should not be called directly; instead, it should be preferred to call
can_create.- Parameters:
obj – An (unsaved) instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to create the object, otherwiseFalse.- Return type:
bool
- can_delete(obj)[source]
Checks whether this user (self) has permission to delete a particular model instance (obj).
This method should be overridden by classes that inherit from KolibriBaseUserMixin.
- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to delete the object, otherwiseFalse.- Return type:
bool
- property can_manage_content
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
- can_read(obj)[source]
Checks whether this user (self) has permission to read a particular model instance (obj).
This method should be overridden by classes that inherit from
KolibriBaseUserMixin.- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to read the object, otherwiseFalse.- Return type:
bool
- can_update(obj)[source]
Checks whether this user (self) has permission to update a particular model instance (obj).
This method should be overridden by classes that inherit from KolibriBaseUserMixin.
- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to update the object, otherwiseFalse.- Return type:
bool
- delete(*args, **kwargs)[source]
Override delete to ensure sessions are cleaned up during hard delete.
- classmethod deserialize(dict_model, sync_filter=None)[source]
Returns an unsaved class object based on the valid properties passed in.
- Parameters:
dict_model (dict) – The model data to deserialize
sync_filter (Filter|None) – The current sync’s filter, if any
- filter_readable(queryset)[source]
Filters a queryset down to only the elements that this user should have permission to read.
- Parameters:
queryset – A
QuerySetinstance that the filtering should be applied to.- Returns:
Filtered
QuerySetincluding only elements that are readable by this user.
- full_facility_import
Returns True if this user is a member of a facility that has been fully imported.
- classmethod get_is_active_q(relation_prefix='')[source]
Returns a Q object that can be used to filter related models by non-deleted users in an abstract way.
- Example:
- If you want to filter lesson assignments by active users, instead of doing:
LessonAssignment.objects.filter(collection__membership__user__date_deleted__isnull=True)
- you can do:
LessonAssignment.objects.filter(FacilityUser.get_is_active_q(relation_prefix=”collection__membership”))
- For direct relations like Role, you can leave the relation_prefix blank:
Role.objects.filter(FacilityUser.get_is_active_q())
This is useful because it abstracts away the actual field name, so if we ever change it, we only need to change it in one place.
- has_role_for_collection(kinds, coll)[source]
Determine whether this user has (at least one of) the specified role kind(s) in relation to the specified
Collection.- Parameters:
kinds (string from kolibri.core.auth.constants.role_kinds.*) – The kind (or kinds) of role to check for, as a string or iterable.
coll – The target
Collectionfor which this user has the roles.
- Returns:
Trueif this user has the specified role kind with respect to the targetCollection, otherwiseFalse.- Return type:
bool
- has_role_for_user(kinds, user)[source]
Determine whether this user has (at least one of) the specified role kind(s) in relation to the specified user.
- Parameters:
user – The user that is the target of the role (for which this user has the roles).
kinds (string from
kolibri.core.auth.constants.role_kinds.*) – The kind (or kinds) of role to check for, as a string or iterable.
- Returns:
Trueif this user has the specified role kind with respect to the target user, otherwiseFalse.- Return type:
bool
- infer_dataset(*args, **kwargs)[source]
This method is used by ensure_dataset to “infer” which dataset should be associated with this instance. It should be overridden in any subclass of
AbstractFacilityDataModel, to define a model-specific inference.
- is_member_of(coll)[source]
Determine whether this user is a member of the specified
Collection.- Parameters:
coll – The
Collectionfor which we are checking this user’s membership.- Returns:
Trueif this user is a member of the specifiedCollection, otherwise False.- Return type:
bool
- property is_staff
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
- property is_superuser
bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- property session_data
Data that is added to the session data at login and during session updates.
- class kolibri.core.auth.models.FacilityUserQuerySet(model=None, query=None, using=None, hints=None)[source]
- delete()[source]
Delete the records in the current QuerySet.
- update(**kwargs)[source]
Update all elements in the current QuerySet, setting all the given fields to the appropriate values.
- class kolibri.core.auth.models.KolibriAnonymousUser[source]
Custom anonymous user that also exposes the same interface as KolibriBaseUserMixin, for consistency.
- can_create_instance(obj)[source]
Checks whether this user (self) has permission to create a particular model instance (obj).
This method should be overridden by classes that inherit from
KolibriBaseUserMixin.In general, unless an instance has already been initialized, this method should not be called directly; instead, it should be preferred to call
can_create.- Parameters:
obj – An (unsaved) instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to create the object, otherwiseFalse.- Return type:
bool
- can_delete(obj)[source]
Checks whether this user (self) has permission to delete a particular model instance (obj).
This method should be overridden by classes that inherit from KolibriBaseUserMixin.
- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to delete the object, otherwiseFalse.- Return type:
bool
- can_read(obj)[source]
Checks whether this user (self) has permission to read a particular model instance (obj).
This method should be overridden by classes that inherit from
KolibriBaseUserMixin.- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to read the object, otherwiseFalse.- Return type:
bool
- can_update(obj)[source]
Checks whether this user (self) has permission to update a particular model instance (obj).
This method should be overridden by classes that inherit from KolibriBaseUserMixin.
- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to update the object, otherwiseFalse.- Return type:
bool
- filter_readable(queryset)[source]
Filters a queryset down to only the elements that this user should have permission to read.
- Parameters:
queryset – A
QuerySetinstance that the filtering should be applied to.- Returns:
Filtered
QuerySetincluding only elements that are readable by this user.
- has_role_for_collection(kinds, coll)[source]
Determine whether this user has (at least one of) the specified role kind(s) in relation to the specified
Collection.- Parameters:
kinds (string from kolibri.core.auth.constants.role_kinds.*) – The kind (or kinds) of role to check for, as a string or iterable.
coll – The target
Collectionfor which this user has the roles.
- Returns:
Trueif this user has the specified role kind with respect to the targetCollection, otherwiseFalse.- Return type:
bool
- has_role_for_user(kinds, user)[source]
Determine whether this user has (at least one of) the specified role kind(s) in relation to the specified user.
- Parameters:
user – The user that is the target of the role (for which this user has the roles).
kinds (string from
kolibri.core.auth.constants.role_kinds.*) – The kind (or kinds) of role to check for, as a string or iterable.
- Returns:
Trueif this user has the specified role kind with respect to the target user, otherwiseFalse.- Return type:
bool
- is_member_of(coll)[source]
Determine whether this user is a member of the specified
Collection.- Parameters:
coll – The
Collectionfor which we are checking this user’s membership.- Returns:
Trueif this user is a member of the specifiedCollection, otherwise False.- Return type:
bool
- property session_data
Data that is added to the session data at login and during session updates.
- class kolibri.core.auth.models.KolibriBaseUserMixin[source]
This mixin is inherited by
KolibriAnonymousUserandFacilityUser. Use a mixin instead of an abstract base class because of difficulties with multiple inheritance and Django’sAbstractBaseUser.- can_create(Model, data)[source]
Checks whether this user (self) has permission to create an instance of Model with the specified attributes (data).
This method defers to the
can_create_instancemethod, and in most cases should not itself be overridden.- Parameters:
Model – A subclass of
django.db.models.Modeldata – A
dictof data to be used in creating an instance of the Model
- Returns:
Trueif this user should have permission to create an instance of Model with the specified data, elseFalse.- Return type:
bool
- can_create_instance(obj)[source]
Checks whether this user (self) has permission to create a particular model instance (obj).
This method should be overridden by classes that inherit from
KolibriBaseUserMixin.In general, unless an instance has already been initialized, this method should not be called directly; instead, it should be preferred to call
can_create.- Parameters:
obj – An (unsaved) instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to create the object, otherwiseFalse.- Return type:
bool
- can_delete(obj)[source]
Checks whether this user (self) has permission to delete a particular model instance (obj).
This method should be overridden by classes that inherit from KolibriBaseUserMixin.
- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to delete the object, otherwiseFalse.- Return type:
bool
- can_read(obj)[source]
Checks whether this user (self) has permission to read a particular model instance (obj).
This method should be overridden by classes that inherit from
KolibriBaseUserMixin.- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to read the object, otherwiseFalse.- Return type:
bool
- can_update(obj)[source]
Checks whether this user (self) has permission to update a particular model instance (obj).
This method should be overridden by classes that inherit from KolibriBaseUserMixin.
- Parameters:
obj – An instance of a Django model, to check permissions for.
- Returns:
Trueif this user should have permission to update the object, otherwiseFalse.- Return type:
bool
- filter_readable(queryset)[source]
Filters a queryset down to only the elements that this user should have permission to read.
- Parameters:
queryset – A
QuerySetinstance that the filtering should be applied to.- Returns:
Filtered
QuerySetincluding only elements that are readable by this user.
- has_role_for(kinds, obj)[source]
Helper function that defers to
has_role_for_userorhas_role_for_collectionbased on the type of object passed in.
- has_role_for_collection(kinds, coll)[source]
Determine whether this user has (at least one of) the specified role kind(s) in relation to the specified
Collection.- Parameters:
kinds (string from kolibri.core.auth.constants.role_kinds.*) – The kind (or kinds) of role to check for, as a string or iterable.
coll – The target
Collectionfor which this user has the roles.
- Returns:
Trueif this user has the specified role kind with respect to the targetCollection, otherwiseFalse.- Return type:
bool
- has_role_for_user(kinds, user)[source]
Determine whether this user has (at least one of) the specified role kind(s) in relation to the specified user.
- Parameters:
user – The user that is the target of the role (for which this user has the roles).
kinds (string from
kolibri.core.auth.constants.role_kinds.*) – The kind (or kinds) of role to check for, as a string or iterable.
- Returns:
Trueif this user has the specified role kind with respect to the target user, otherwiseFalse.- Return type:
bool
- is_member_of(coll)[source]
Determine whether this user is a member of the specified
Collection.- Parameters:
coll – The
Collectionfor which we are checking this user’s membership.- Returns:
Trueif this user is a member of the specifiedCollection, otherwise False.- Return type:
bool
- property session_data
Data that is added to the session data at login and during session updates.
- class kolibri.core.auth.models.LearnerGroup(id, _morango_dirty_bit, _morango_source_id, _morango_partition, dataset, name, parent, kind)[source]
- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetname (CharField) – Name
parent_id (ForeignKey to
~) – Parentkind (CharField) – Kind
- exception DoesNotExist
- exception MultipleObjectsReturned
- get_classroom()[source]
Gets the
LearnerGroup’s parentClassroom.- Returns:
A
Classroominstance.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.Membership(*args, **kwargs)[source]
A
FacilityUsercan be marked as a member of aCollectionthrough aMembershipobject. Being a member of aCollectionalso means being a member of all theCollectionsabove thatCollectionin the tree (i.e. if you are a member of aLearnerGroup, you are also a member of theClassroomthat contains thatLearnerGroup, and of theFacilitythat contains thatClassroom).- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetuser_id (ForeignKey to
~) – Usercollection_id (TreeForeignKey to
~) – Collection
- exception DoesNotExist
- exception MultipleObjectsReturned
- calculate_partition()[source]
Should return a string specifying this model instance’s partition, using self.ID_PLACEHOLDER in place of its own ID, if needed.
- calculate_source_id()[source]
Should return a string that uniquely defines the model instance or None for a random uuid.
- infer_dataset(*args, **kwargs)[source]
This method is used by ensure_dataset to “infer” which dataset should be associated with this instance. It should be overridden in any subclass of
AbstractFacilityDataModel, to define a model-specific inference.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.Role(*args, **kwargs)[source]
A
FacilityUsercan have a role for a particularCollectionthrough aRoleobject, which also stores the “kind” of theRole(currently, one of “admin” or “coach”). Having a role for aCollectionalso implies having that role for all sub-collections of thatCollection(i.e. all theCollectionsbelow it in the tree).- Parameters:
id (UUIDField) – Id
_morango_dirty_bit (BooleanField) – morango dirty bit
_morango_source_id (CharField) – morango source id
_morango_partition (CharField) – morango partition
dataset_id (ForeignKey to
~) – Datasetuser_id (ForeignKey to
~) – Usercollection_id (TreeForeignKey to
~) – Collectionkind (CharField) – Kind
- exception DoesNotExist
- exception MultipleObjectsReturned
- calculate_partition()[source]
Should return a string specifying this model instance’s partition, using self.ID_PLACEHOLDER in place of its own ID, if needed.
- calculate_source_id()[source]
Should return a string that uniquely defines the model instance or None for a random uuid.
- infer_dataset(*args, **kwargs)[source]
This method is used by ensure_dataset to “infer” which dataset should be associated with this instance. It should be overridden in any subclass of
AbstractFacilityDataModel, to define a model-specific inference.
- save(*args, **kwargs)[source]
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class kolibri.core.auth.models.Session(*args, **kwargs)[source]
Custom session model with user_id tracking for session management. Inherits from Django’s AbstractBaseSession and adds user_id field.
- Parameters:
session_key (CharField) – Session key
session_data (TextField) – Session data
expire_date (DateTimeField) – Expire date
user_id (UUIDField) – User id
- exception DoesNotExist
- exception MultipleObjectsReturned
- class kolibri.core.auth.models.SessionRouter[source]
Determine how to route database calls for custom Session model.
- class kolibri.core.auth.models.SoftDeletedFacilityUserModelManager(*args, **kwargs)[source]
Custom manager for FacilityUser that only returns users who have a non-NULL value in their date_deleted field.
- get_queryset()[source]
Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.