Source code for codegrade.models.attest_defense_question_frame

"""The module that defines the ``AttestDefenseQuestionFrame`` 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 .attest_defense_dimension_weights import AttestDefenseDimensionWeights


[docs] @dataclass(kw_only=True) class AttestDefenseQuestionFrame: """How the defense of an Attest Defense assignment frames its questions.""" #: How often the defense asks about each dimension. This is `None` for a #: reader who may not edit the assignment, so that a student cannot prepare #: the defense from the weights. weights: t.Optional[AttestDefenseDimensionWeights] #: The number of questions the defense asks. count: int 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( "weights", rqa.Nullable( parsers.ParserFor.make(AttestDefenseDimensionWeights) ), doc="How often the defense asks about each dimension. This is `None` for a reader who may not edit the assignment, so that a student cannot prepare the defense from the weights.", ), rqa.RequiredArgument( "count", rqa.SimpleValue.int, doc="The number of questions the defense asks.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "weights": to_dict(self.weights), "count": to_dict(self.count), } return res @classmethod def from_dict( cls: t.Type[AttestDefenseQuestionFrame], d: t.Dict[str, t.Any] ) -> AttestDefenseQuestionFrame: parsed = cls.data_parser.try_parse(d) res = cls( weights=parsed.weights, count=parsed.count, ) res.raw_data = d return res