Source code for codegrade.models.attest_defense_start_window
"""The module that defines the ``AttestDefenseStartWindow`` 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 AttestDefenseStartWindow:
"""The window in which a student has to start the defense."""
#: How long the student has to start the defense once the questions are
#: ready, in whole seconds.
duration: int
#: A fixed moment before which the student also has to start. A student
#: whose questions are ready after it gets the whole `duration`. This is
#: `None` when the teacher set no fixed moment.
ends_at: t.Optional[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(
"duration",
rqa.SimpleValue.int,
doc="How long the student has to start the defense once the questions are ready, in whole seconds.",
),
rqa.RequiredArgument(
"ends_at",
rqa.Nullable(rqa.RichValue.DateTime),
doc="A fixed moment before which the student also has to start. A student whose questions are ready after it gets the whole `duration`. This is `None` when the teacher set no fixed moment.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"duration": to_dict(self.duration),
"ends_at": to_dict(self.ends_at),
}
return res
@classmethod
def from_dict(
cls: t.Type[AttestDefenseStartWindow], d: t.Dict[str, t.Any]
) -> AttestDefenseStartWindow:
parsed = cls.data_parser.try_parse(d)
res = cls(
duration=parsed.duration,
ends_at=parsed.ends_at,
)
res.raw_data = d
return res