Source code for codegrade.models.attest_assignment

"""The module that defines the ``AttestAssignment`` 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_assignment import BaseAssignment


[docs] @dataclass(kw_only=True) class AttestAssignment(BaseAssignment): """The serialization of an Attest assignment.""" #: The type of the assignment, always `attest` here. type: t.Literal["attest"] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: BaseAssignment.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "type", rqa.StringEnum("attest"), doc="The type of the assignment, always `attest` here.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "type": to_dict(self.type), "id": to_dict(self.id), "name": to_dict(self.name), "created_at": to_dict(self.created_at), "course_id": to_dict(self.course_id), "has_multiple_timeframes": to_dict(self.has_multiple_timeframes), "is_lti": to_dict(self.is_lti), "has_description": to_dict(self.has_description), "restrictions": to_dict(self.restrictions), "timeframe": to_dict(self.timeframe), "grade_availability": to_dict(self.grade_availability), } return res @classmethod def from_dict( cls: t.Type[AttestAssignment], d: t.Dict[str, t.Any] ) -> AttestAssignment: parsed = cls.data_parser.try_parse(d) res = cls( type=parsed.type, id=parsed.id, name=parsed.name, created_at=parsed.created_at, course_id=parsed.course_id, has_multiple_timeframes=parsed.has_multiple_timeframes, is_lti=parsed.is_lti, has_description=parsed.has_description, restrictions=parsed.restrictions, timeframe=parsed.timeframe, grade_availability=parsed.grade_availability, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): import datetime from .assignment_restriction import AssignmentRestriction from .fixed_grade_availability import FixedGradeAvailability from .timeframe_like import TimeframeLike