Source code for codegrade.models.redirect_preparation_result

"""The module that defines the ``RedirectPreparationResult`` 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 .redirect_preparation import RedirectPreparation


[docs] @dataclass(kw_only=True) class RedirectPreparationResult(RedirectPreparation): """The onboarding redirect produced by one preparation. Extends the `redirect` preparation the restriction advertises, so the tag the client switched on and the tag it gets back are the same literal, declared once in `cg_proctoring`. """ #: Where to send the student's browser to onboard. This is the provider's #: URL, not a CodeGrade one. redirect_url: str raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: RedirectPreparation.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "redirect_url", rqa.SimpleValue.str, doc="Where to send the student's browser to onboard. This is the provider's URL, not a CodeGrade one.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "redirect_url": to_dict(self.redirect_url), "tag": to_dict(self.tag), } return res @classmethod def from_dict( cls: t.Type[RedirectPreparationResult], d: t.Dict[str, t.Any] ) -> RedirectPreparationResult: parsed = cls.data_parser.try_parse(d) res = cls( redirect_url=parsed.redirect_url, tag=parsed.tag, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): pass