AlekSIS
AlekSIS

Core data models

class aleksis.core.models.Activity(*args, **kwargs)[source]

Activity of a user to trace some actions done in AlekSIS in displayable form.

Parameters
  • id (BigAutoField) – Id

  • created (AutoCreatedField) – Created

  • modified (AutoLastModifiedField) – Modified

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • user (ForeignKey to Person) – User

  • title (CharField) – Title

  • description (TextField) – Description

  • app (CharField) – Application

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.AdditionalField(*args, **kwargs)[source]

An additional field that can be linked to a group.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • title (CharField) – Title of field

  • field_type (CharField) – Type of field

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.Announcement(*args, **kwargs)[source]

Announcement model.

Persistent announcement to display to groups or persons in various places during a specific time range.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • title (CharField) – Title

  • description (TextField) – Description

  • link (URLField) – Link to detailed view

  • valid_from (DateTimeField) – Date and time from when to show

  • valid_until (DateTimeField) – Date and time until when to show

exception DoesNotExist
exception MultipleObjectsReturned
get_recipients_for_model(obj)[source]

Get all recipients.

Get all recipients for this announcement with a special content type (provided through model)

Return type

Sequence[Model]

property recipient_persons

Return a list of Persons this announcement is relevant for.

Return type

Sequence[Person]

class aleksis.core.models.AnnouncementQuerySet(model=None, query=None, using=None, hints=None)[source]

Queryset for announcements providing time-based utility functions.

at_time(when=None)[source]

Get all announcements at a certain time.

Return type

QuerySet

for_person(person)[source]

Get all announcements for one person.

Return type

List

on_date(when=None)[source]

Get all announcements at a certain date.

Return type

QuerySet

relevant_for(obj)[source]

Get all relevant announcements.

Get a QuerySet with all announcements relevant for a certain Model (e.g. a Group) or a set of models in a QuerySet.

Return type

QuerySet

within_days(start, stop)[source]

Get all announcements valid for a set of days.

Return type

QuerySet

class aleksis.core.models.AnnouncementRecipient(*args, **kwargs)[source]

Announcement recipient model.

Generalisation of a recipient for an announcement, used to wrap arbitrary objects that can receive announcements.

Contract: Objects to serve as recipient have a property announcement_recipients returning a flat list of Person objects.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • announcement (ForeignKey to Announcement) – Announcement

  • content_type (ForeignKey to ContentType) – Content type

  • recipient_id (PositiveIntegerField) – Recipient id

exception DoesNotExist
exception MultipleObjectsReturned
property persons

Return a list of Persons selected by this recipient object.

If the recipient is a Person, return that object. If not, it returns the list from the announcement_recipients field on the target model.

Return type

Sequence[Person]

class aleksis.core.models.CustomMenu(*args, **kwargs)[source]

A custom menu to display in the footer.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • name (CharField) – Menu id

exception DoesNotExist
exception MultipleObjectsReturned
classmethod get_default(name)[source]

Get a menu by name or create if it does not exist.

class aleksis.core.models.CustomMenuItem(*args, **kwargs)[source]

Single item in a custom menu.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • menu (ForeignKey to CustomMenu) – Menu

  • name (CharField) – Name

  • url (URLField) – Link

  • icon (CharField) – Icon

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.DashboardWidget(*args, **kwargs)[source]

Base class for dashboard widgets on the index page.

To implement a widget, add a model that subclasses DashboardWidget, sets the template and implements the get_context method to return a dictionary to be passed as context to the template.

If your widget does not add any database fields, you should mark it as a proxy model.

You can provide a Media meta class with custom JS and CSS files which will be added to html head. For further information on media definition see https://docs.djangoproject.com/en/3.0/topics/forms/media/

Example:

from django.forms.widgets import Media

from aleksis.core.models import DashboardWidget

class MyWidget(DashboardWidget):
    template = "myapp/widget.html"

    def get_context(self, request):
        context = {"some_content": "foo"}
        return context

    class Meta:
        proxy = True

    media = Media(css={
            'all': ('pretty.css',)
        },
        js=('animations.js', 'actions.js')
    )
Parameters
  • id (BigAutoField) – Id

  • polymorphic_ctype (ForeignKey to ContentType) – Polymorphic ctype

  • title (CharField) – Widget title

  • active (BooleanField) – Activate widget

  • broken (BooleanField) – Widget is broken

  • size_s (PositiveSmallIntegerField) – Size on mobile devices. <= 600 px, 12 columns

  • size_m (PositiveSmallIntegerField) – Size on tablet devices. > 600 px, 12 columns

  • size_l (PositiveSmallIntegerField) – Size on desktop devices. > 992 px, 12 columns

  • size_xl (PositiveSmallIntegerField) – Size on large desktop devices. > 1200 px>, 12 columns

exception DoesNotExist
exception MultipleObjectsReturned
get_context(request)[source]

Get the context dictionary to pass to the widget template.

static get_media(widgets)[source]

Return all media required to render the selected widgets.

get_template()[source]

Get template.

Get the template to render the widget with. Defaults to the template attribute, but can be overridden to allow more complex template generation scenarios. If the widget is marked as broken, the template_broken attribute will be returned.

class aleksis.core.models.DashboardWidgetOrder(id, site, extended_data, widget, person, order, default)[source]
Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • widget (ForeignKey to DashboardWidget) – Dashboard widget

  • person (ForeignKey to Person) – Person

  • order (PositiveIntegerField) – Order

  • default (BooleanField) – Part of the default dashboard

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.DataCheckResult(*args, **kwargs)[source]

Save the result of a data check for a specific object.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • check (CharField) – Related data check task

  • content_type (ForeignKey to ContentType) – Content type

  • object_id (CharField) – Object id

  • solved (BooleanField) – Issue solved

  • sent (BooleanField) – Notification sent

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.DummyPerson(*args, **kwargs)[source]

A dummy person that is not stored into the database.

Used to temporarily inject a Person object into a User.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • user (OneToOneField to User) – Linked user

  • first_name (CharField) – First name

  • last_name (CharField) – Last name

  • additional_name (CharField) – Additional name(s)

  • short_name (CharField) – Short name

  • street (CharField) – Street

  • housenumber (CharField) – Street number

  • postal_code (CharField) – Postal code

  • place (CharField) – Place

  • phone_number (PhoneNumberField) – Home phone

  • mobile_number (PhoneNumberField) – Mobile phone

  • email (EmailField) – E-mail address

  • date_of_birth (DateField) – Date of birth

  • place_of_birth (CharField) – Place of birth

  • sex (CharField) – Sex

  • photo (ImageField) – Photo. This is an official photo, used for official documents and for internal use cases.

  • avatar (ImageField) – Display picture / avatar. This is a picture or an avatar for public display.

  • primary_group (ForeignKey to Group) – Primary group

  • description (TextField) – Description

  • guardians (ManyToManyField) – Guardians / parents

exception DoesNotExist
exception MultipleObjectsReturned
save(*args, **kwargs)[source]

Ensure all functionality of our extensions that needs saving gets it.

class aleksis.core.models.ExternalLinkWidget(id, polymorphic_ctype, title, active, broken, size_s, size_m, size_l, size_xl, dashboardwidget_ptr, url, icon_url)[source]
Parameters
  • id (BigAutoField) – Id

  • polymorphic_ctype (ForeignKey to ContentType) – Polymorphic ctype

  • title (CharField) – Widget title

  • active (BooleanField) – Activate widget

  • broken (BooleanField) – Widget is broken

  • size_s (PositiveSmallIntegerField) – Size on mobile devices. <= 600 px, 12 columns

  • size_m (PositiveSmallIntegerField) – Size on tablet devices. > 600 px, 12 columns

  • size_l (PositiveSmallIntegerField) – Size on desktop devices. > 992 px, 12 columns

  • size_xl (PositiveSmallIntegerField) – Size on large desktop devices. > 1200 px>, 12 columns

  • dashboardwidget_ptr (OneToOneField to DashboardWidget) – Dashboardwidget ptr

  • url (URLField) – Url

  • icon_url (URLField) – Icon url

exception DoesNotExist
exception MultipleObjectsReturned
get_context(request)[source]

Get the context dictionary to pass to the widget template.

class aleksis.core.models.GlobalPermissions(*args, **kwargs)[source]

Container for global permissions.

Parameters

id (BigAutoField) – Id

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.Group(*args, **kwargs)[source]

Group model.

Any kind of group of persons in a school, including, but not limited classes, clubs, and the like.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • school_term (ForeignKey to SchoolTerm) – Linked school term

  • name (CharField) – Long name

  • short_name (CharField) – Short name

  • group_type (ForeignKey to GroupType) – Type of group

  • photo (ImageField) – Photo. This is an official photo, used for official documents and for internal use cases.

  • avatar (ImageField) – Display picture / avatar. This is a picture or an avatar for public display.

  • members (ManyToManyField) – Members

  • owners (ManyToManyField) – Owners

  • parent_groups (ManyToManyField) – Parent groups

  • additional_fields (ManyToManyField) – Additional fields

exception DoesNotExist
exception MultipleObjectsReturned
property announcement_recipients

Flat list of all members and owners to fulfill announcement API contract.

property child_groups_recursive

Get all child groups recursively.

Return type

CTEQuerySet

property django_group

Get Django group for this group.

get_absolute_url()[source]

Get the URL o a view representing this model instance.

Return type

str

property get_group_stats

Get stats about a given group

Return type

dict

property members_recursive

Get all members of this group and its child groups.

Return type

QuerySet

property owners_recursive

Get all ownerss of this group and its parent groups.

Return type

QuerySet

property parent_groups_recursive

Get all parent groups recursively.

Return type

CTEQuerySet

refresh_from_db(using=None, fields=None)

Reload field values from the database.

By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.

Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.

When accessing deferred fields of an instance, the deferred loading of the field will call this method.

save(force=False, *args, **kwargs)[source]

Ensure all functionality of our extensions that needs saving gets it.

save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.

The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.

class aleksis.core.models.GroupPreferenceModel(*args, **kwargs)[source]

Preference model to hold pereferences valid for members of a group.

Parameters
  • id (BigAutoField) – Id

  • section (CharField) – Section name

  • name (CharField) – Name

  • raw_value (TextField) – Raw value

  • instance (ForeignKey to Group) – Instance

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.GroupType(*args, **kwargs)[source]

Group type model.

Descriptive type of a group; used to tag groups and for apps to distinguish how to display or handle a certain group.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • name (CharField) – Title of type

  • description (CharField) – Description

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.Notification(*args, **kwargs)[source]

Notification to submit to a user.

Parameters
  • id (BigAutoField) – Id

  • created (AutoCreatedField) – Created

  • modified (AutoLastModifiedField) – Modified

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • sender (CharField) – Sender

  • recipient (ForeignKey to Person) – Recipient

  • title (CharField) – Title

  • description (TextField) – Description

  • link (URLField) – Link

  • read (BooleanField) – Read

  • sent (BooleanField) – Sent

exception DoesNotExist
exception MultipleObjectsReturned
save(**kwargs)[source]

Ensure all functionality of our extensions that needs saving gets it.

class aleksis.core.models.OAuthAccessToken(*args, **kwargs)[source]

Placeholder for customising the AccessToken model.

Parameters
  • id (BigAutoField) – Id

  • user (ForeignKey to User) – User

  • source_refresh_token (OneToOneField to OAuthRefreshToken) – Source refresh token

  • token (CharField) – Token

  • id_token (OneToOneField to OAuthIDToken) – Id token

  • application (ForeignKey to OAuthApplication) – Application

  • expires (DateTimeField) – Expires

  • scope (TextField) – Scope

  • created (DateTimeField) – Created

  • updated (DateTimeField) – Updated

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.OAuthApplication(*args, **kwargs)[source]

Modified OAuth application class that supports Grant Flows configured in preferences.

Parameters
  • id (BigAutoField) – Id

  • client_id (CharField) – Client id

  • user (ForeignKey to User) – User

  • redirect_uris (TextField) – Redirect uris. Allowed URIs list, space separated

  • client_type (CharField) – Client type

  • client_secret (CharField) – Client secret

  • name (CharField) – Name

  • skip_authorization (BooleanField) – Skip authorization

  • created (DateTimeField) – Created

  • updated (DateTimeField) – Updated

  • algorithm (CharField) – Algorithm

  • authorization_grant_type (CharField) – Authorization grant type

  • allowed_scopes (ArrayField) – Allowed scopes that clients can request

  • icon (ImageField) – Icon. This image will be shown as icon in the authorization flow. It should be squared.

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.OAuthGrant(*args, **kwargs)[source]

Placeholder for customising the Grant model.

Parameters
  • id (BigAutoField) – Id

  • user (ForeignKey to User) – User

  • code (CharField) – Code

  • application (ForeignKey to OAuthApplication) – Application

  • expires (DateTimeField) – Expires

  • redirect_uri (TextField) – Redirect uri

  • scope (TextField) – Scope

  • created (DateTimeField) – Created

  • updated (DateTimeField) – Updated

  • code_challenge (CharField) – Code challenge

  • code_challenge_method (CharField) – Code challenge method

  • nonce (CharField) – Nonce

  • claims (TextField) – Claims

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.OAuthIDToken(*args, **kwargs)[source]

Placeholder for customising the IDToken model.

Parameters
  • id (BigAutoField) – Id

  • user (ForeignKey to User) – User

  • jti (UUIDField) – Jwt token id

  • application (ForeignKey to OAuthApplication) – Application

  • expires (DateTimeField) – Expires

  • scope (TextField) – Scope

  • created (DateTimeField) – Created

  • updated (DateTimeField) – Updated

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.OAuthRefreshToken(*args, **kwargs)[source]

Placeholder for customising the RefreshToken model.

Parameters
  • id (BigAutoField) – Id

  • user (ForeignKey to User) – User

  • token (CharField) – Token

  • application (ForeignKey to OAuthApplication) – Application

  • access_token (OneToOneField to OAuthAccessToken) – Access token

  • created (DateTimeField) – Created

  • updated (DateTimeField) – Updated

  • revoked (DateTimeField) – Revoked

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.PDFFile(*args, **kwargs)[source]

Link to a rendered PDF file.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • person (ForeignKey to Person) – Owner

  • expires_at (DateTimeField) – File expires at

  • html_file (FileField) – Generated html file

  • file (FileField) – Generated pdf file

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.Person(*args, **kwargs)[source]

Person model.

A model describing any person related to a school, including, but not limited to, students, teachers and guardians (parents).

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • user (OneToOneField to User) – Linked user

  • first_name (CharField) – First name

  • last_name (CharField) – Last name

  • additional_name (CharField) – Additional name(s)

  • short_name (CharField) – Short name

  • street (CharField) – Street

  • housenumber (CharField) – Street number

  • postal_code (CharField) – Postal code

  • place (CharField) – Place

  • phone_number (PhoneNumberField) – Home phone

  • mobile_number (PhoneNumberField) – Mobile phone

  • email (EmailField) – E-mail address

  • date_of_birth (DateField) – Date of birth

  • place_of_birth (CharField) – Place of birth

  • sex (CharField) – Sex

  • photo (ImageField) – Photo. This is an official photo, used for official documents and for internal use cases.

  • avatar (ImageField) – Display picture / avatar. This is a picture or an avatar for public display.

  • primary_group (ForeignKey to Group) – Primary group

  • description (TextField) – Description

  • guardians (ManyToManyField) – Guardians / parents

exception DoesNotExist
exception MultipleObjectsReturned
property addressing_name

Full name of person in format configured for addressing.

Return type

str

property age

Age of the person at current time.

auto_select_primary_group(pattern=None, field=None, force=False)[source]

Auto-select the primary group among the groups the person is member of.

Uses either the pattern passed as argument, or the pattern configured system-wide.

Does not do anything if either no pattern is defined or the user already has a primary group, unless force is True.

Return type

None

property full_name

Full name of person in last name, first name order.

Return type

str

get_absolute_url()[source]

Get the URL o a view representing this model instance.

Return type

str

property mail_sender

E-mail sender in “Name <email>” format.

Return type

str

property mail_sender_via

E-mail sender for via addresses, in “Name via Site <email>” format.

Return type

str

property member_of_recursive

Get all groups this person is a member of, recursively.

Return type

QuerySet

notify_about_changed_data(changed_fields, recipients=None)[source]

Notify (configured) recipients about changed data of this person.

property owner_of_recursive

Get all groups this person is a member of, recursively.

Return type

QuerySet

property primary_group_short_name

Return the short_name field of the primary group related object.

Return type

Optional[str]

refresh_from_db(using=None, fields=None)

Reload field values from the database.

By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.

Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.

When accessing deferred fields of an instance, the deferred loading of the field will call this method.

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

Ensure all functionality of our extensions that needs saving gets it.

save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.

The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.

property unread_notifications

Get all unread notifications for this person.

Return type

QuerySet

property unread_notifications_count

Return the count of unread notifications for this person.

Return type

int

class aleksis.core.models.PersonGroupThrough(*args, **kwargs)[source]

Through table for many-to-many relationship of group members.

It does not have any fields on its own; these are generated upon instantiation by inspecting the additional fields selected for the linked group.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • group (ForeignKey to Group) – Group

  • person (ForeignKey to Person) – Person

exception DoesNotExist
exception MultipleObjectsReturned
__init__(*args, **kwargs)[source]

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

class aleksis.core.models.PersonInvitation(*args, **kwargs)[source]

Custom model for invitations to allow to generate invitations codes without email address.

Parameters
  • id (BigAutoField) – Id

  • accepted (BooleanField) – Accepted

  • key (CharField) – Key

  • sent (DateTimeField) – Sent

  • inviter (ForeignKey to User) – Inviter

  • email (EmailField) – E-mail address

  • person (ForeignKey to Person) – Person

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.PersonPreferenceModel(*args, **kwargs)[source]

Preference model to hold pereferences valid for a person.

Parameters
  • id (BigAutoField) – Id

  • section (CharField) – Section name

  • name (CharField) – Name

  • raw_value (TextField) – Raw value

  • instance (ForeignKey to Person) – Instance

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.SchoolTerm(*args, **kwargs)[source]

School term model.

This is used to manage start and end times of a school term and link data to it.

Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • name (CharField) – Name

  • date_start (DateField) – Start date

  • date_end (DateField) – End date

exception DoesNotExist
exception MultipleObjectsReturned
clean()[source]

Ensure there is only one school term at each point of time.

class aleksis.core.models.SitePreferenceModel(*args, **kwargs)[source]

Preference model to hold pereferences valid for a site.

Parameters
  • id (BigAutoField) – Id

  • section (CharField) – Section name

  • name (CharField) – Name

  • raw_value (TextField) – Raw value

  • instance (ForeignKey to Site) – Instance

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.TaskUserAssignment(id, site, extended_data, task_result, user)[source]
Parameters
  • id (BigAutoField) – Id

  • site (ForeignKey to Site) – Site

  • extended_data (JSONField) – Extended data

  • task_result (ForeignKey to TaskResult) – Task result

  • user (ForeignKey to User) – Task user

exception DoesNotExist
exception MultipleObjectsReturned
class aleksis.core.models.UserAdditionalAttributes(*args, **kwargs)[source]

Additional attributes for Django user accounts.

These attributes are explicitly linked to a User, not to a Person.

Parameters
  • id (BigAutoField) – Id

  • user (OneToOneField to User) – Linked user

  • attributes (JSONField) – Additional attributes

exception DoesNotExist
exception MultipleObjectsReturned
classmethod get_user_attribute(username, attribute, default=None)[source]

Get a user attribute for a user by name.

Return type

Any

classmethod set_user_attribute(username, attribute, value)[source]

Set a user attribute for a user by name.

Raises DoesNotExist if a username for a non-existing Django user is passed.

aleksis.core.models.save_group_on_m2m_changed(sender, instance, action, reverse, model, pk_set, **kwargs)[source]

Ensure user and group data is synced to Django’s models.

AlekSIS maintains personal information and group meta-data / membership in its Person and Group models. As third-party libraries have no knowledge about this, we need to keep django.contrib.auth in sync.

This signal handler triggers a save of group objects whenever a membership changes. The save() code will decide whether to update the Django objects or not.

Return type

None