Source code for codegrade.models.virtual_user

"""The module that defines the ``VirtualUser`` 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_user import BaseUser


[docs] @dataclass(kw_only=True) class VirtualUser(BaseUser): """A group's virtual user serialised without its wrapped `group`.""" #: The username of this group user. System-generated group identifier, not #: personally identifying — always rendered. username: str #: This user is never a test student. is_test_student: t.Literal[False] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: BaseUser.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "username", rqa.SimpleValue.str, doc="The username of this group user. System-generated group identifier, not personally identifying — always rendered.", ), rqa.RequiredArgument( "is_test_student", rqa.LiteralBoolean(False), doc="This user is never a test student.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "username": to_dict(self.username), "is_test_student": to_dict(self.is_test_student), "id": to_dict(self.id), "tenant_id": to_dict(self.tenant_id), } return res @classmethod def from_dict( cls: t.Type[VirtualUser], d: t.Dict[str, t.Any] ) -> VirtualUser: parsed = cls.data_parser.try_parse(d) res = cls( username=parsed.username, is_test_student=parsed.is_test_student, id=parsed.id, tenant_id=parsed.tenant_id, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): pass