Aller au contenu

Schemas

ShortUeList = TypeAdapter(list[UtbmShortUeSchema]) module-attribute

UE

Bases: Model

Contains infos about an UE (course).

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 UE, 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 UE, else False.
    """
    return self.comments.filter(author=user).exists()

UtbmShortUeSchema

Bases: Schema

Short representation of an UE 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

SemesterUeState

Bases: Schema

The state of the UE during either autumn or spring semester

UtbmFullUeSchema

Bases: Schema

Long representation of an UE in the UTBM API.

SimpleUeSchema

Bases: ModelSchema

Our minimal representation of an UE.

UeSchema

Bases: ModelSchema

Our complete representation of an UE

UeFilterSchema

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 UE code
        return Q(code__istartswith=value)

    qs = list(
        SearchQuerySet()
        .models(UE)
        .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, UE 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, UE 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)