Source code for codegrade.models.entry_overview_entry
"""The module that defines the ``EntryOverviewEntry`` 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 .user import User, UserParser
[docs]
@dataclass
class EntryOverviewEntry:
"""A single entry in the restriction entries listing."""
user: User
#: How many times the user has entered this restriction.
use_count: int
#: The per-student override limit, or null if no override is set.
override_limit: t.Optional[int]
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(
"user",
UserParser,
doc="",
),
rqa.RequiredArgument(
"use_count",
rqa.SimpleValue.int,
doc="How many times the user has entered this restriction.",
),
rqa.RequiredArgument(
"override_limit",
rqa.Nullable(rqa.SimpleValue.int),
doc="The per-student override limit, or null if no override is set.",
),
).use_readable_describe(True)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"user": to_dict(self.user),
"use_count": to_dict(self.use_count),
"override_limit": to_dict(self.override_limit),
}
return res
@classmethod
def from_dict(
cls: t.Type[EntryOverviewEntry], d: t.Dict[str, t.Any]
) -> EntryOverviewEntry:
parsed = cls.data_parser.try_parse(d)
res = cls(
user=parsed.user,
use_count=parsed.use_count,
override_limit=parsed.override_limit,
)
res.raw_data = d
return res