Source code for codegrade.models.enroll_data_by_id

"""The module that defines the ``EnrollDataById`` 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 .base_enroll_data import BaseEnrollData
from .user_input_by_id import UserInputById


[docs] @dataclass(kw_only=True) class EnrollDataById(UserInputById, BaseEnrollData): """Enrol payload referencing the user by id.""" raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: UserInputById.data_parser.parser.combine( BaseEnrollData.data_parser.parser ).combine(rqa.FixedMapping()) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "user_id": to_dict(self.user_id), "by": to_dict(self.by), "role_id": to_dict(self.role_id), } return res @classmethod def from_dict( cls: t.Type[EnrollDataById], d: t.Dict[str, t.Any] ) -> EnrollDataById: parsed = cls.data_parser.try_parse(d) res = cls( user_id=parsed.user_id, by=parsed.by, role_id=parsed.role_id, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): pass