Newer
Older
from __future__ import annotations
__copyright__ = "Copyright (C) 2014 Andreas Kloeckner"
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from typing import cast
from xml.etree.ElementTree import Element, tostring
import dulwich.objects
import dulwich.repo
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.urls import NoReverseMatch
from django.utils.timezone import now
from django.utils.translation import gettext as _
from markdown.extensions import Extension
from markdown.treeprocessors import Treeprocessor
from course.constants import ATTRIBUTES_FILENAME
from course.validation import Blob_ish, Tree_ish
from relate.utils import Struct, SubdirRepoWrapper, dict_to_struct
Andreas Klöckner
committed
CACHE_KEY_ROOT = "py4"
Andreas Klöckner
committed
# {{{ mypy
from collections.abc import Callable, Collection, Mapping
from typing import (
TYPE_CHECKING,
Any,
if TYPE_CHECKING:
Andreas Klöckner
committed
# for mypy
from course.models import Course, Participation
from course.page.base import PageBase
from course.validation import FileSystemFakeRepoTree, ValidationContext
from relate.utils import Repo_ish
Andreas Klöckner
committed
Date_ish = datetime.datetime | datetime.date
Datespec = datetime.datetime | datetime.date | str
Andreas Klöckner
committed
class ChunkRulesDesc(Struct):
if_has_role: list[str]
if_before: Datespec
if_after: Datespec
if_in_facility: str
if_has_participation_tags_any: list[str]
if_has_participation_tags_all: list[str]
roles: list[str]
start: Datespec
end: Datespec
shown: bool
weight: float
Andreas Klöckner
committed
class ChunkDesc(Struct):
weight: float
shown: bool
title: str | None
content: str
rules: list[ChunkRulesDesc]
html_content: str
Andreas Klöckner
committed
class StaticPageDesc(Struct):
chunks: list[ChunkDesc]
content: str
Andreas Klöckner
committed
class CourseDesc(StaticPageDesc):
pass
# }}}
# {{{ mypy: flow start rule
Andreas Klöckner
committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""Rules that govern when a new session may be started and whether
existing sessions may be listed.
Found in the ``start`` attribute of :class:`FlowRulesDesc`.
.. rubric:: Conditions
.. attribute:: if_after
(Optional) A :ref:`datespec <datespec>` that determines a date/time
after which this rule applies.
.. attribute:: if_before
(Optional) A :ref:`datespec <datespec>` that determines a date/time
before which this rule applies.
.. attribute:: if_has_role
(Optional) A list of a subset of the roles defined in the course, by
default ``unenrolled``, ``ta``, ``student``, ``instructor``.
.. attribute:: if_has_participation_tags_any
(Optional) A list of participation tags. Rule applies when the
participation has at least one tag in this list.
.. attribute:: if_has_participation_tags_all
(Optional) A list of participation tags. Rule applies if only the
participation's tags include all items in this list.
.. attribute:: if_in_facility
(Optional) Name of a facility known to the RELATE web page. This rule allows
(for example) restricting flow starting based on whether a user is physically
located in a computer-based testing center (which RELATE can
recognize based on IP ranges).
.. attribute:: if_has_in_progress_session
(Optional) A Boolean (True/False) value, indicating that the rule only
applies if the participant has an in-progress session.
.. attribute:: if_has_session_tagged
(Optional) An identifier (or ``null``) indicating that the rule only applies
if the participant has a session with the corresponding tag.
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
.. attribute:: if_has_fewer_sessions_than
(Optional) An integer. The rule applies if the participant has fewer
than this number of sessions.
.. attribute:: if_has_fewer_tagged_sessions_than
(Optional) An integer. The rule applies if the participant has fewer
than this number of sessions with access rule tags.
.. attribute:: if_signed_in_with_matching_exam_ticket
(Optional) The rule applies if the participant signed in with an exam
ticket matching this flow.
.. rubric:: Rules specified
.. attribute:: may_start_new_session
(Mandatory) A Boolean (True/False) value indicating whether, if the
rule applies, the participant may start a new session.
.. attribute:: may_list_existing_sessions
(Mandatory) A Boolean (True/False) value indicating whether, if the
rule applies, the participant may view a list of existing sessions.
.. attribute:: tag_session
(Optional) An identifier that will be applied to a newly-created
session as a "tag". This can be used by
:attr:`FlowSessionAccessRuleDesc.if_has_tag` and
:attr:`FlowSessionGradingRuleDesc.if_has_tag`.
.. attribute:: default_expiration_mode
(Optional) One of :class:`~course.constants.flow_session_expiration_mode`.
The expiration mode applied when a session is first created or rolled
over.
Loading
Loading full blame...