Source code for codegrade.models.restriction_set_session_lockdown_with_entry_window
"""The module that defines the ``RestrictionSetSessionLockdownWithEntryWindow`` 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 .entry_window import EntryWindow
[docs]
@dataclass(kw_only=True)
class RestrictionSetSessionLockdownWithEntryWindow:
"""The serialized form of an active session lockdown.
Mirrors :class:`SetSessionLockdown` but additionally carries the global
configured entry window. The window is only serialized here; the
input/property :class:`SetSessionLockdown` stays window-free as the window
is written through :meth:`set_entry_window`.
"""
#: Discriminator tag.
tag: t.Literal["set"]
#: Maximum number of password entries per student.
max_entries: int
#: Whether heartbeat enforcement is enabled for this lockdown.
heartbeat_enforced: bool
#: The global configured entry window, or `None` when the feature is
#: disabled, the viewer is anonymous, or no complete window is stored.
entry_window: t.Optional[EntryWindow]
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(
"tag",
rqa.StringEnum("set"),
doc="Discriminator tag.",
),
rqa.RequiredArgument(
"max_entries",
rqa.SimpleValue.int,
doc="Maximum number of password entries per student.",
),
rqa.RequiredArgument(
"heartbeat_enforced",
rqa.SimpleValue.bool,
doc="Whether heartbeat enforcement is enabled for this lockdown.",
),
rqa.RequiredArgument(
"entry_window",
rqa.Nullable(parsers.ParserFor.make(EntryWindow)),
doc="The global configured entry window, or `None` when the feature is disabled, the viewer is anonymous, or no complete window is stored.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"tag": to_dict(self.tag),
"max_entries": to_dict(self.max_entries),
"heartbeat_enforced": to_dict(self.heartbeat_enforced),
"entry_window": to_dict(self.entry_window),
}
return res
@classmethod
def from_dict(
cls: t.Type[RestrictionSetSessionLockdownWithEntryWindow],
d: t.Dict[str, t.Any],
) -> RestrictionSetSessionLockdownWithEntryWindow:
parsed = cls.data_parser.try_parse(d)
res = cls(
tag=parsed.tag,
max_entries=parsed.max_entries,
heartbeat_enforced=parsed.heartbeat_enforced,
entry_window=parsed.entry_window,
)
res.raw_data = d
return res