Source code for codegrade.models.editor_configuration_enabled_input
"""The module that defines the ``EditorConfigurationEnabledInput`` 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 cg_maybe import Maybe, Nothing
from cg_maybe.utils import maybe_from_nullable
from ..utils import to_dict
[docs]
@dataclass(kw_only=True)
class EditorConfigurationEnabledInput:
"""The editor is enabled for this assignment."""
#: The tag for this data.
tag: t.Literal["enabled"]
#: The maximum number of characters allowed in a single paste; `0` blocks
#: all pastes and `null` clears the limit. Omit to leave the current limit
#: unchanged.
max_paste_size: Maybe[t.Optional[int]] = Nothing
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("enabled"),
doc="The tag for this data.",
),
rqa.OptionalArgument(
"max_paste_size",
rqa.Nullable(rqa.SimpleValue.int),
doc="The maximum number of characters allowed in a single paste; `0` blocks all pastes and `null` clears the limit. Omit to leave the current limit unchanged.",
),
)
)
def __post_init__(self) -> None:
getattr(super(), "__post_init__", lambda: None)()
self.max_paste_size = maybe_from_nullable(self.max_paste_size)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"tag": to_dict(self.tag),
}
if self.max_paste_size.is_just:
res["max_paste_size"] = to_dict(self.max_paste_size.value)
return res
@classmethod
def from_dict(
cls: t.Type[EditorConfigurationEnabledInput], d: t.Dict[str, t.Any]
) -> EditorConfigurationEnabledInput:
parsed = cls.data_parser.try_parse(d)
res = cls(
tag=parsed.tag,
max_paste_size=parsed.max_paste_size,
)
res.raw_data = d
return res