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 (but not a DeviceOwner) 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 as FacilityUsers, 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(*args, **kwargs)[source]

Cleans all fields and raises a ValidationError containing a dict of all validation errors if any occur.

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 a KolibriValidationError exception as well.

full_clean(*args, **kwargs)[source]

Calls clean_fields, clean, and validate_unique, on the model, and raises a ValidationError for any errors that occurred.

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]

Saves 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 AdHocGroup is a collection kind that can be used in an assignment to create a group that is specific to a single Lesson or Exam.

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

  • name (CharField) – Name

  • parent_id (ForeignKey to ~) – Parent

  • kind (CharField) – Kind

exception DoesNotExist
exception MultipleObjectsReturned
classmethod deserialize(dict_model)[source]

Returns an unsaved class object based on the valid properties passed in.

get_classroom()[source]

Gets the AdHocGroup’s parent Classroom.

Returns:

A Classroom instance.

save(*args, **kwargs)[source]

Saves 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 ~) – Dataset

  • name (CharField) – Name

  • parent_id (ForeignKey to ~) – Parent

  • kind (CharField) – Kind

exception DoesNotExist
exception MultipleObjectsReturned
get_facility()[source]

Gets the Classroom’s parent Facility.

Returns:

A Facility instance.

get_individual_learners_group()[source]

Returns a QuerySet of AdHocGroups.

:return A AdHocGroup QuerySet.

get_learner_groups()[source]

Returns a QuerySet of LearnerGroups associated with this Classroom.

Returns:

A LearnerGroup QuerySet.

save(*args, **kwargs)[source]

Saves 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]

Collections are hierarchical groups of FacilityUsers, used for grouping users and making decisions about permissions. FacilityUsers can have roles for one or more Collections, by way of obtaining Roles associated with those Collections. Collections can belong to other Collections, and user membership in a Collection is conferred through Memberships. Collections are 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 ~) – Dataset

  • name (CharField) – Name

  • parent_id (ForeignKey to ~) – Parent

  • kind (CharField) – Kind

exception DoesNotExist
exception MultipleObjectsReturned
add_member(user)[source]

Create a Membership associating the provided user with this Collection. If the Membership object already exists, just return that, without changing anything.

Parameters:

user – The FacilityUser to add to this Collection.

Returns:

The Membership object (possibly new) that associates the user with the Collection.

add_role(user, role_kind)[source]

Create a Role associating 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 FacilityUser to associate with this Collection.

  • role_kind – The kind of role to give the user with respect to this Collection.

Returns:

The Role object (possibly new) that associates the user with the Collection.

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(*args, **kwargs)[source]

Cleans all fields and raises a ValidationError containing a dict of all validation errors if any occur.

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 Membership objects associating the provided user with this Collection.

Parameters:

user – The FacilityUser to remove from this Collection.

Returns:

True if a Membership was removed, False if there was no matching Membership to remove.

remove_role(user, role_kind)[source]

Remove any Role objects associating the provided user with this Collection, with the specified kind of role.

Parameters:
  • user – The FacilityUser to dissociate from this Collection (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]

Saves 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 ~) – Dataset

  • name (CharField) – Name

  • parent_id (ForeignKey to ~) – Parent

  • kind (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 a KolibriValidationError exception 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]

Saves 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]

FacilityDataset stores high-level metadata and settings for a particular Facility. It is also the model that all models storing facility data (data that is associated with a particular facility, and that inherits from AbstractFacilityDataModel) foreign key onto, to indicate that they belong to this particular Facility.

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

  • 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]

Saves 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.FacilityUser(*args, **kwargs)[source]

FacilityUser is the fundamental object of the auth app. These users represent the main users, and can be associated with a hierarchy of Collections through Memberships and Roles, 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 ~) – Dataset

  • username (CharField) – Required. 254 characters or fewer.

  • full_name (CharField) – Full name

  • date_joined (DateTimeTzField) – Date joined

  • facility_id (ForeignKey to ~) – Facility

  • gender (CharField) – Gender

  • birth_year (CharField) – Birth year

  • id_number (CharField) – Id number

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 KolibriAbstractBaseUser.

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:

True if this user should have permission to create the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to delete the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to read the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to update the object, otherwise False.

Return type:

bool

classmethod deserialize(dict_model)[source]

Returns an unsaved class object based on the valid properties passed in.

filter_readable(queryset)[source]

Filters a queryset down to only the elements that this user should have permission to read.

Parameters:

queryset – A QuerySet instance that the filtering should be applied to.

Returns:

Filtered QuerySet including 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.

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 Collection for which this user has the roles.

Returns:

True if this user has the specified role kind with respect to the target Collection, otherwise False.

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:

True if this user has the specified role kind with respect to the target user, otherwise False.

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 Collection for which we are checking this user’s membership.

Returns:

True if this user is a member of the specified Collection, 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.

property session_data

Data that is added to the session data at login and during session updates.

class kolibri.core.auth.models.KolibriAbstractBaseUser(*args, **kwargs)[source]

Our custom user type, derived from AbstractBaseUser as described in the Django docs. Draws liberally from django.contrib.auth.AbstractUser, except we exclude some fields we don’t care about, like email.

This model is an abstract model, and is inherited by FacilityUser.

Parameters:
  • password (CharField) – Password

  • last_login (DateTimeField) – Last login

  • username (CharField) – Required. 254 characters or fewer.

  • full_name (CharField) – Full name

  • date_joined (DateTimeTzField) – Date joined

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_instance method, and in most cases should not itself be overridden.

Parameters:
  • Model – A subclass of django.db.models.Model

  • data – A dict of data to be used in creating an instance of the Model

Returns:

True if this user should have permission to create an instance of Model with the specified data, else False.

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 KolibriAbstractBaseUser.

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:

True if this user should have permission to create the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to delete the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to read the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to update the object, otherwise False.

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 QuerySet instance that the filtering should be applied to.

Returns:

Filtered QuerySet including only elements that are readable by this user.

has_role_for(kinds, obj)[source]

Helper function that defers to has_role_for_user or has_role_for_collection based 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 Collection for which this user has the roles.

Returns:

True if this user has the specified role kind with respect to the target Collection, otherwise False.

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:

True if this user has the specified role kind with respect to the target user, otherwise False.

Return type:

bool

is_member_of(coll)[source]

Determine whether this user is a member of the specified Collection.

Parameters:

coll – The Collection for which we are checking this user’s membership.

Returns:

True if this user is a member of the specified Collection, 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.KolibriAnonymousUser[source]

Custom anonymous user that also exposes the same interface as KolibriAbstractBaseUser, for consistency.

Parameters:
  • password (CharField) – Password

  • last_login (DateTimeField) – Last login

  • full_name (CharField) – Full name

  • date_joined (DateTimeTzField) – Date joined

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 KolibriAbstractBaseUser.

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:

True if this user should have permission to create the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to delete the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to read the object, otherwise False.

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 KolibriAbstractBaseUser.

Parameters:

obj – An instance of a Django model, to check permissions for.

Returns:

True if this user should have permission to update the object, otherwise False.

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 QuerySet instance that the filtering should be applied to.

Returns:

Filtered QuerySet including 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 Collection for which this user has the roles.

Returns:

True if this user has the specified role kind with respect to the target Collection, otherwise False.

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:

True if this user has the specified role kind with respect to the target user, otherwise False.

Return type:

bool

is_member_of(coll)[source]

Determine whether this user is a member of the specified Collection.

Parameters:

coll – The Collection for which we are checking this user’s membership.

Returns:

True if this user is a member of the specified Collection, 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 ~) – Dataset

  • name (CharField) – Name

  • parent_id (ForeignKey to ~) – Parent

  • kind (CharField) – Kind

exception DoesNotExist
exception MultipleObjectsReturned
get_classroom()[source]

Gets the LearnerGroup’s parent Classroom.

Returns:

A Classroom instance.

save(*args, **kwargs)[source]

Saves 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 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 tree (i.e. if you are a member of a LearnerGroup, you are also a member of the Classroom that contains that LearnerGroup, and of the Facility that contains that Classroom).

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

  • user_id (ForeignKey to ~) – User

  • collection_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]

Saves 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 FacilityUser can have a role for a particular Collection through a Role object, which also stores the “kind” of the Role (currently, one of “admin” or “coach”). Having a role for a Collection also implies having that role for all sub-collections of that Collection (i.e. all the Collections below 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 ~) – Dataset

  • user_id (ForeignKey to ~) – User

  • collection_id (TreeForeignKey to ~) – Collection

  • kind (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]

Saves 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.