Source code for codegrade.models.extended_code_assignment

"""The module that defines the ``ExtendedCodeAssignment`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import datetime
import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa

from .. import parsers
from ..utils import to_dict
from .assignment_editor_settings import AssignmentEditorSettings
from .assignment_peer_feedback_settings import AssignmentPeerFeedbackSettings
from .assignment_submission_mode import AssignmentSubmissionMode
from .assignment_terminal_settings_disabled_as_json import (
    AssignmentTerminalSettingsDisabledAsJSON,
)
from .assignment_terminal_settings_enabled_as_json import (
    AssignmentTerminalSettingsEnabledAsJSON,
)
from .code_assignment import CodeAssignment
from .extended_assignment_extra import ExtendedAssignmentExtra
from .webhook_configuration_disabled_as_json import (
    WebhookConfigurationDisabledAsJSON,
)
from .webhook_configuration_enabled_as_json import (
    WebhookConfigurationEnabledAsJSON,
)


[docs] @dataclass(kw_only=True) class ExtendedCodeAssignment(CodeAssignment, ExtendedAssignmentExtra): """The full version of a code assignment.""" #: Deprecated. Always `false`, login links have been removed. send_login_links: t.Literal[False] #: The id of the AutoTest configuration connected to this assignment. This #: will always be given if there is a configuration connected to this #: assignment, even if you do not have permission to see the configuration #: itself. auto_test_id: t.Optional[int] #: Can you upload files to this assignment. files_upload_enabled: bool #: Settings for the git connection to this assignment. webhook_configuration: t.Union[ WebhookConfigurationEnabledAsJSON, WebhookConfigurationDisabledAsJSON ] #: The terminal settings of this assignment's code editor. terminal_settings: t.Union[ AssignmentTerminalSettingsEnabledAsJSON, AssignmentTerminalSettingsDisabledAsJSON, ] #: Can you use the editor for this assignment. editor_upload_enabled: bool #: The code-editor settings for this assignment. `null` when the editor is #: disabled for it. editor_settings: t.Optional[AssignmentEditorSettings] #: The maximum amount of submission a student may create, inclusive. The #: value `null` indicates that there is no limit. max_submissions: t.Optional[int] #: The time period in which a person can submit at most #: `amount_in_cool_off_period` amount. cool_off_period: datetime.timedelta #: The maximum amount of time a user can submit within #: `amount_in_cool_off_period`. This value is always greater than or equal #: to 0, if this value is 0 a user can submit an unlimited amount of time. amount_in_cool_off_period: int #: The peer feedback settings for this assignment. If `null` this #: assignment is not a peer feedback assignment. peer_feedback_settings: t.Optional[AssignmentPeerFeedbackSettings] #: Optionally a glob for a file that should be loaded first in the file #: viewer. There is no guarantee that any file actually matches this glob. file_to_load_first: t.Optional[str] #: The tab the submission page opens on. `null` when the assignment leaves #: it to the tenant default. default_submission_tab: t.Optional[ t.Literal["auto-test", "code", "feedback-overview", "peer-feedback"] ] #: Which submission mode is set for the assignment. submission_mode: AssignmentSubmissionMode #: The moment reminder emails will be sent. This will be `None` if you #: don't have the permission to see this or if it is unset. reminder_time: t.Optional[datetime.datetime] #: The kind of reminder that will be sent. If you don't have the permission #: to see this it will always be `null`. If this is not set it will also be #: `null`. done_type: t.Optional[str] #: The email where the done email will be sent to. This will be `null` if #: you do not have permission to see this information. done_email: t.Optional[str] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: CodeAssignment.data_parser.parser.combine( ExtendedAssignmentExtra.data_parser.parser ).combine( rqa.FixedMapping( rqa.RequiredArgument( "send_login_links", rqa.LiteralBoolean(False), doc="Deprecated. Always `false`, login links have been removed.", ), rqa.RequiredArgument( "auto_test_id", rqa.Nullable(rqa.SimpleValue.int), doc="The id of the AutoTest configuration connected to this assignment. This will always be given if there is a configuration connected to this assignment, even if you do not have permission to see the configuration itself.", ), rqa.RequiredArgument( "files_upload_enabled", rqa.SimpleValue.bool, doc="Can you upload files to this assignment.", ), rqa.RequiredArgument( "webhook_configuration", parsers.make_union( parsers.ParserFor.make( WebhookConfigurationEnabledAsJSON ), parsers.ParserFor.make( WebhookConfigurationDisabledAsJSON ), ), doc="Settings for the git connection to this assignment.", ), rqa.RequiredArgument( "terminal_settings", parsers.make_union( parsers.ParserFor.make( AssignmentTerminalSettingsEnabledAsJSON ), parsers.ParserFor.make( AssignmentTerminalSettingsDisabledAsJSON ), ), doc="The terminal settings of this assignment's code editor.", ), rqa.RequiredArgument( "editor_upload_enabled", rqa.SimpleValue.bool, doc="Can you use the editor for this assignment.", ), rqa.RequiredArgument( "editor_settings", rqa.Nullable( parsers.ParserFor.make(AssignmentEditorSettings) ), doc="The code-editor settings for this assignment. `null` when the editor is disabled for it.", ), rqa.RequiredArgument( "max_submissions", rqa.Nullable(rqa.SimpleValue.int), doc="The maximum amount of submission a student may create, inclusive. The value `null` indicates that there is no limit.", ), rqa.RequiredArgument( "cool_off_period", rqa.RichValue.TimeDelta, doc="The time period in which a person can submit at most `amount_in_cool_off_period` amount.", ), rqa.RequiredArgument( "amount_in_cool_off_period", rqa.SimpleValue.int, doc="The maximum amount of time a user can submit within `amount_in_cool_off_period`. This value is always greater than or equal to 0, if this value is 0 a user can submit an unlimited amount of time.", ), rqa.RequiredArgument( "peer_feedback_settings", rqa.Nullable( parsers.ParserFor.make(AssignmentPeerFeedbackSettings) ), doc="The peer feedback settings for this assignment. If `null` this assignment is not a peer feedback assignment.", ), rqa.RequiredArgument( "file_to_load_first", rqa.Nullable(rqa.SimpleValue.str), doc="Optionally a glob for a file that should be loaded first in the file viewer. There is no guarantee that any file actually matches this glob.", ), rqa.RequiredArgument( "default_submission_tab", rqa.Nullable( rqa.StringEnum( "auto-test", "code", "feedback-overview", "peer-feedback", ) ), doc="The tab the submission page opens on. `null` when the assignment leaves it to the tenant default.", ), rqa.RequiredArgument( "submission_mode", rqa.EnumValue(AssignmentSubmissionMode), doc="Which submission mode is set for the assignment.", ), rqa.RequiredArgument( "reminder_time", rqa.Nullable(rqa.RichValue.DateTime), doc="The moment reminder emails will be sent. This will be `None` if you don't have the permission to see this or if it is unset.", ), rqa.RequiredArgument( "done_type", rqa.Nullable(rqa.SimpleValue.str), doc="The kind of reminder that will be sent. If you don't have the permission to see this it will always be `null`. If this is not set it will also be `null`.", ), rqa.RequiredArgument( "done_email", rqa.Nullable(rqa.SimpleValue.str), doc="The email where the done email will be sent to. This will be `null` if you do not have permission to see this information.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "send_login_links": to_dict(self.send_login_links), "auto_test_id": to_dict(self.auto_test_id), "files_upload_enabled": to_dict(self.files_upload_enabled), "webhook_configuration": to_dict(self.webhook_configuration), "terminal_settings": to_dict(self.terminal_settings), "editor_upload_enabled": to_dict(self.editor_upload_enabled), "editor_settings": to_dict(self.editor_settings), "max_submissions": to_dict(self.max_submissions), "cool_off_period": to_dict(self.cool_off_period), "amount_in_cool_off_period": to_dict( self.amount_in_cool_off_period ), "peer_feedback_settings": to_dict(self.peer_feedback_settings), "file_to_load_first": to_dict(self.file_to_load_first), "default_submission_tab": to_dict(self.default_submission_tab), "submission_mode": to_dict(self.submission_mode), "reminder_time": to_dict(self.reminder_time), "done_type": to_dict(self.done_type), "done_email": to_dict(self.done_email), "type": to_dict(self.type), "kind": to_dict(self.kind), "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), "cgignore": to_dict(self.cgignore), "cgignore_version": to_dict(self.cgignore_version), "fixed_max_rubric_points": to_dict(self.fixed_max_rubric_points), "max_grade": to_dict(self.max_grade), "grading": to_dict(self.grading), "group_set": to_dict(self.group_set), "lms_name": to_dict(self.lms_name), "division_parent_id": to_dict(self.division_parent_id), "anonymized_grading": to_dict(self.anonymized_grading), } return res @classmethod def from_dict( cls: t.Type[ExtendedCodeAssignment], d: t.Dict[str, t.Any] ) -> ExtendedCodeAssignment: parsed = cls.data_parser.try_parse(d) res = cls( send_login_links=parsed.send_login_links, auto_test_id=parsed.auto_test_id, files_upload_enabled=parsed.files_upload_enabled, webhook_configuration=parsed.webhook_configuration, terminal_settings=parsed.terminal_settings, editor_upload_enabled=parsed.editor_upload_enabled, editor_settings=parsed.editor_settings, max_submissions=parsed.max_submissions, cool_off_period=parsed.cool_off_period, amount_in_cool_off_period=parsed.amount_in_cool_off_period, peer_feedback_settings=parsed.peer_feedback_settings, file_to_load_first=parsed.file_to_load_first, default_submission_tab=parsed.default_submission_tab, submission_mode=parsed.submission_mode, reminder_time=parsed.reminder_time, done_type=parsed.done_type, done_email=parsed.done_email, type=parsed.type, kind=parsed.kind, 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, cgignore=parsed.cgignore, cgignore_version=parsed.cgignore_version, fixed_max_rubric_points=parsed.fixed_max_rubric_points, max_grade=parsed.max_grade, grading=parsed.grading, group_set=parsed.group_set, lms_name=parsed.lms_name, division_parent_id=parsed.division_parent_id, anonymized_grading=parsed.anonymized_grading, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): from .assignment_anonymization_algo import AssignmentAnonymizationAlgo from .assignment_percentage_grading_settings import ( AssignmentPercentageGradingSettings, ) from .assignment_points_grading_settings import ( AssignmentPointsGradingSettings, ) from .assignment_restriction import AssignmentRestriction from .base_assignment import BaseAssignment from .cg_ignore_version import CGIgnoreVersion from .fixed_grade_availability import FixedGradeAvailability from .group_set import GroupSet from .submission_validator_input_data import SubmissionValidatorInputData from .timeframe_like import TimeframeLike