Source code for codegrade.models.create_block_registration_domain_data

"""The module that defines the ``CreateBlockRegistrationDomainData`` 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


[docs] @dataclass class CreateBlockRegistrationDomainData: """ """ #: The type of rule. type: t.Literal["block"] #: The email domain to match. domain: str #: Whether to also match subdomains. match_subdomains: bool = True 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( "type", rqa.StringEnum("block"), doc="The type of rule.", ), rqa.RequiredArgument( "domain", rqa.SimpleValue.str, doc="The email domain to match.", ), rqa.DefaultArgument( "match_subdomains", rqa.SimpleValue.bool, doc="Whether to also match subdomains.", default=lambda: True, ), ).use_readable_describe(True) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "type": to_dict(self.type), "domain": to_dict(self.domain), "match_subdomains": to_dict(self.match_subdomains), } return res @classmethod def from_dict( cls: t.Type[CreateBlockRegistrationDomainData], d: t.Dict[str, t.Any] ) -> CreateBlockRegistrationDomainData: parsed = cls.data_parser.try_parse(d) res = cls( type=parsed.type, domain=parsed.domain, match_subdomains=parsed.match_subdomains, ) res.raw_data = d return res