Source code for codegrade.models.confirm_registered_response

"""The module that defines the ``ConfirmRegisteredResponse`` 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 .user_login_response import UserLoginResponse


[docs] @dataclass class ConfirmRegisteredResponse(UserLoginResponse): """Response when a registration is confirmed and the user is created.""" #: Always `'registered'`. status: t.Literal["registered"] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: UserLoginResponse.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "status", rqa.StringEnum("registered"), doc="Always `'registered'`.", ), ) ).use_readable_describe(True) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "status": to_dict(self.status), "user": to_dict(self.user), "access_token": to_dict(self.access_token), "restrictions": to_dict(self.restrictions), "expires_at": to_dict(self.expires_at), } return res @classmethod def from_dict( cls: t.Type[ConfirmRegisteredResponse], d: t.Dict[str, t.Any] ) -> ConfirmRegisteredResponse: parsed = cls.data_parser.try_parse(d) res = cls( status=parsed.status, user=parsed.user, access_token=parsed.access_token, restrictions=parsed.restrictions, expires_at=parsed.expires_at, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): import datetime from .extended_user import ExtendedUser from .session_restriction_data import SessionRestrictionData