"""The module that defines the ``LTIAssignmentLaunchToOpenSubmission`` 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 .. import parsers
from ..utils import to_dict
from .extended_work import ExtendedWork
[docs]@dataclass
class LTIAssignmentLaunchToOpenSubmission:
"""A submission should be opened as the result of this launch."""
#: A submission should be opened.
type: t.Literal["submission"]
#: The reason the submission is to be opened. Direct will send the user to
#: a submission if given a submission_id. Latest will send the user to
#: their latest submission.
reason: t.Literal["direct", "latest"]
#: The submission to open.
submission: ExtendedWork
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar = rqa.Lazy(
lambda: rqa.FixedMapping(
rqa.RequiredArgument(
"type",
rqa.StringEnum("submission"),
doc="A submission should be opened.",
),
rqa.RequiredArgument(
"reason",
rqa.StringEnum("direct", "latest"),
doc="The reason the submission is to be opened. Direct will send the user to a submission if given a submission_id. Latest will send the user to their latest submission.",
),
rqa.RequiredArgument(
"submission",
parsers.ParserFor.make(ExtendedWork),
doc="The submission to open.",
),
).use_readable_describe(True)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"type": to_dict(self.type),
"reason": to_dict(self.reason),
"submission": to_dict(self.submission),
}
return res
@classmethod
def from_dict(
cls: t.Type[LTIAssignmentLaunchToOpenSubmission], d: t.Dict[str, t.Any]
) -> LTIAssignmentLaunchToOpenSubmission:
parsed = cls.data_parser.try_parse(d)
res = cls(
type=parsed.type,
reason=parsed.reason,
submission=parsed.submission,
)
res.raw_data = d
return res