Aller au contenu

Schemas

ShortUvList = TypeAdapter(list[UtbmShortUvSchema]) module-attribute

UV

Bases: Model

Contains infos about an UV (course).

is_owned_by(user)

Can be created by superuser, root or pedagogy admin user.

Source code in pedagogy/models.py
def is_owned_by(self, user):
    """Can be created by superuser, root or pedagogy admin user."""
    return user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)

can_be_viewed_by(user)

Only visible by subscribers.

Source code in pedagogy/models.py
def can_be_viewed_by(self, user):
    """Only visible by subscribers."""
    return user.is_subscribed

has_user_already_commented(user)

Help prevent multiples comments from the same user.

This function checks that no other comment has been posted by a specified user.

Returns:

Type Description
bool

True if the user has already posted a comment on this UV, else False.

Source code in pedagogy/models.py
def has_user_already_commented(self, user: User) -> bool:
    """Help prevent multiples comments from the same user.

    This function checks that no other comment has been posted by a specified user.

    Returns:
        True if the user has already posted a comment on this UV, else False.
    """
    return self.comments.filter(author=user).exists()

UtbmShortUvSchema

Bases: Schema

Short representation of an UV in the UTBM API.

Notes

This schema holds only the fields we actually need. The UTBM API returns more data than that.

WorkloadSchema

Bases: Schema

SemesterUvState

Bases: Schema

The state of the UV during either autumn or spring semester

UtbmFullUvSchema

Bases: Schema

Long representation of an UV in the UTBM API.

SimpleUvSchema

Bases: ModelSchema

Our minimal representation of an UV.

UvSchema

Bases: ModelSchema

Our complete representation of an UV

UvFilterSchema

Bases: FilterSchema

Special filter for the search text.

It does a full text search if available.

Source code in pedagogy/schemas.py
def filter_search(self, value: str | None) -> Q:
    """Special filter for the search text.

    It does a full text search if available.
    """
    if not value:
        return Q()

    if len(value) < 3 or (len(value) < 5 and any(c.isdigit() for c in value)):
        # Likely to be an UV code
        return Q(code__istartswith=value)

    qs = list(
        SearchQuerySet()
        .models(UV)
        .autocomplete(auto=html.escape(value))
        .values_list("pk", flat=True)
    )

    return Q(id__in=qs)

filter_semester(value)

Special filter for the semester.

If either "SPRING" or "AUTUMN" is given, UV that are available during "AUTUMN_AND_SPRING" will be filtered.

Source code in pedagogy/schemas.py
def filter_semester(self, value: set[str] | None) -> Q:
    """Special filter for the semester.

    If either "SPRING" or "AUTUMN" is given, UV that are available
    during "AUTUMN_AND_SPRING" will be filtered.
    """
    if not value:
        return Q()
    value.add("AUTUMN_AND_SPRING")
    return Q(semester__in=value)