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`

    121
    122
    123
    124
    125
    126
    127
    128
    129
    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`

### `filter_search(value)`

Special filter for the search text.

It does a full text search if available.

Source code in `pedagogy/schemas.py`

    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    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`

    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    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)