Source code for codegrade.models.assignment_restriction
"""The module that defines the ``AssignmentRestriction`` 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 ..utils import to_dict
from .restriction_mixin import RestrictionMixin
[docs]
@dataclass
class AssignmentRestriction(RestrictionMixin):
"""The restrictions for the assignment."""
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: RestrictionMixin.data_parser.parser.combine(
rqa.FixedMapping()
).use_readable_describe(True)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"password": to_dict(self.password),
}
return res
@classmethod
def from_dict(
cls: t.Type[AssignmentRestriction], d: t.Dict[str, t.Any]
) -> AssignmentRestriction:
parsed = cls.data_parser.try_parse(d)
res = cls(
password=parsed.password,
)
res.raw_data = d
return res
import os
if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"):
from .restriction_mixin_not_set_password import (
RestrictionMixinNotSetPassword,
)
from .restriction_mixin_set_password import RestrictionMixinSetPassword