Source code for codegrade.models.attest_defense_timing

"""The module that defines the ``AttestDefenseTiming`` 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 .attest_defense_start_window import AttestDefenseStartWindow


[docs] @dataclass(kw_only=True) class AttestDefenseTiming: """The timing of the defense of an Attest Defense assignment.""" #: The time the student gets for each question, in whole seconds. time_per_question: int #: The window in which the student has to start the defense. start_window: AttestDefenseStartWindow 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( "time_per_question", rqa.SimpleValue.int, doc="The time the student gets for each question, in whole seconds.", ), rqa.RequiredArgument( "start_window", parsers.ParserFor.make(AttestDefenseStartWindow), doc="The window in which the student has to start the defense.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "time_per_question": to_dict(self.time_per_question), "start_window": to_dict(self.start_window), } return res @classmethod def from_dict( cls: t.Type[AttestDefenseTiming], d: t.Dict[str, t.Any] ) -> AttestDefenseTiming: parsed = cls.data_parser.try_parse(d) res = cls( time_per_question=parsed.time_per_question, start_window=parsed.start_window, ) res.raw_data = d return res