Source code for codegrade.models.exam_environment_management
"""The module that defines the ``ExamEnvironmentManagement`` 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 .provider_description import ProviderDescription
[docs]
@dataclass(kw_only=True)
class ExamEnvironmentManagement:
"""What the management UI needs to configure an exam environment."""
#: The live attached provider, or `None`. An archived (detached) config is
#: deliberately not "attached" (mirrors `proctoring.is_live`).
attached: t.Optional[ProviderDescription]
#: The providers this tenant may attach. Schoolyear appears iff the tenant
#: has a Schoolyear provider row.
available_providers: t.Sequence[ProviderDescription]
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(
"attached",
rqa.Nullable(parsers.ParserFor.make(ProviderDescription)),
doc='The live attached provider, or `None`. An archived (detached) config is deliberately not "attached" (mirrors `proctoring.is_live`).',
),
rqa.RequiredArgument(
"available_providers",
rqa.List(parsers.ParserFor.make(ProviderDescription)),
doc="The providers this tenant may attach. Schoolyear appears iff the tenant has a Schoolyear provider row.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"attached": to_dict(self.attached),
"available_providers": to_dict(self.available_providers),
}
return res
@classmethod
def from_dict(
cls: t.Type[ExamEnvironmentManagement], d: t.Dict[str, t.Any]
) -> ExamEnvironmentManagement:
parsed = cls.data_parser.try_parse(d)
res = cls(
attached=parsed.attached,
available_providers=parsed.available_providers,
)
res.raw_data = d
return res