Source code for codegrade.models.exam_calendar_entry

"""The module that defines the ``ExamCalendarEntry`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import datetime
import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa

from ..utils import to_dict


[docs] @dataclass(kw_only=True) class ExamCalendarEntry: """A single scheduled exam.""" #: The tenant of the course running the exam. tenant_id: str #: The name of that tenant. tenant_name: str #: The course running the exam. course_id: int #: The name of that course. course_name: str #: When the first student may enter, per-student overrides included. span_starts_at: datetime.datetime #: When the last student must have left, per-student overrides included. span_ends_at: datetime.datetime #: When the entry window configured on the course opens. entry_starts_at: datetime.datetime #: When the entry window configured on the course closes. entry_ends_at: datetime.datetime raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: rqa.FixedMapping( rqa.RequiredArgument( "tenant_id", rqa.SimpleValue.str, doc="The tenant of the course running the exam.", ), rqa.RequiredArgument( "tenant_name", rqa.SimpleValue.str, doc="The name of that tenant.", ), rqa.RequiredArgument( "course_id", rqa.SimpleValue.int, doc="The course running the exam.", ), rqa.RequiredArgument( "course_name", rqa.SimpleValue.str, doc="The name of that course.", ), rqa.RequiredArgument( "span_starts_at", rqa.RichValue.DateTime, doc="When the first student may enter, per-student overrides included.", ), rqa.RequiredArgument( "span_ends_at", rqa.RichValue.DateTime, doc="When the last student must have left, per-student overrides included.", ), rqa.RequiredArgument( "entry_starts_at", rqa.RichValue.DateTime, doc="When the entry window configured on the course opens.", ), rqa.RequiredArgument( "entry_ends_at", rqa.RichValue.DateTime, doc="When the entry window configured on the course closes.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "tenant_id": to_dict(self.tenant_id), "tenant_name": to_dict(self.tenant_name), "course_id": to_dict(self.course_id), "course_name": to_dict(self.course_name), "span_starts_at": to_dict(self.span_starts_at), "span_ends_at": to_dict(self.span_ends_at), "entry_starts_at": to_dict(self.entry_starts_at), "entry_ends_at": to_dict(self.entry_ends_at), } return res @classmethod def from_dict( cls: t.Type[ExamCalendarEntry], d: t.Dict[str, t.Any] ) -> ExamCalendarEntry: parsed = cls.data_parser.try_parse(d) res = cls( tenant_id=parsed.tenant_id, tenant_name=parsed.tenant_name, course_id=parsed.course_id, course_name=parsed.course_name, span_starts_at=parsed.span_starts_at, span_ends_at=parsed.span_ends_at, entry_starts_at=parsed.entry_starts_at, entry_ends_at=parsed.entry_ends_at, ) res.raw_data = d return res