Source code for codegrade.models.restriction_exam_environment_artifact_preparation
"""The module that defines the ``RestrictionExamEnvironmentArtifactPreparation`` 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
from .artifact_preparation import ArtifactPreparation
[docs]
@dataclass(kw_only=True)
class RestrictionExamEnvironmentArtifactPreparation(ArtifactPreparation):
"""The student must install a file before the exam starts."""
#: The moment from which the requesting user may set up the exam
#: environment, derived from their effective entry window. `None` when no
#: window resolves and preparing is therefore not time-bounded. Preparing
#: before this moment is refused, so a UI offering the set-up action should
#: disable it until then.
opens_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: ArtifactPreparation.data_parser.parser.combine(
rqa.FixedMapping(
rqa.RequiredArgument(
"opens_at",
rqa.Nullable(rqa.RichValue.DateTime),
doc="The moment from which the requesting user may set up the exam environment, derived from their effective entry window. `None` when no window resolves and preparing is therefore not time-bounded. Preparing before this moment is refused, so a UI offering the set-up action should disable it until then.",
),
)
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"opens_at": to_dict(self.opens_at),
"tag": to_dict(self.tag),
}
return res
@classmethod
def from_dict(
cls: t.Type[RestrictionExamEnvironmentArtifactPreparation],
d: t.Dict[str, t.Any],
) -> RestrictionExamEnvironmentArtifactPreparation:
parsed = cls.data_parser.try_parse(d)
res = cls(
opens_at=parsed.opens_at,
tag=parsed.tag,
)
res.raw_data = d
return res
import os
if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"):
pass