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 typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa

from .. import parsers
from ..utils import to_dict
from .course import Course
from .entry_window import EntryWindow
from .tenant import Tenant


[docs] @dataclass(kw_only=True) class ExamCalendarEntry: """A single scheduled exam.""" #: The course running the exam. course: Course #: The tenant of that course. tenant: Tenant #: When the first student may enter and the last must have left, widened by #: the per-student overrides the reader may see. span: EntryWindow #: The entry window configured on the course. entry: EntryWindow #: Whether the overrides of the course widened the span in this entry. widened: bool 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( "course", parsers.ParserFor.make(Course), doc="The course running the exam.", ), rqa.RequiredArgument( "tenant", parsers.ParserFor.make(Tenant), doc="The tenant of that course.", ), rqa.RequiredArgument( "span", parsers.ParserFor.make(EntryWindow), doc="When the first student may enter and the last must have left, widened by the per-student overrides the reader may see.", ), rqa.RequiredArgument( "entry", parsers.ParserFor.make(EntryWindow), doc="The entry window configured on the course.", ), rqa.RequiredArgument( "widened", rqa.SimpleValue.bool, doc="Whether the overrides of the course widened the span in this entry.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "course": to_dict(self.course), "tenant": to_dict(self.tenant), "span": to_dict(self.span), "entry": to_dict(self.entry), "widened": to_dict(self.widened), } 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( course=parsed.course, tenant=parsed.tenant, span=parsed.span, entry=parsed.entry, widened=parsed.widened, ) res.raw_data = d return res