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 collections.abc import Iterable
from typing import (
TYPE_CHECKING,
Any,
cast,
Andreas Klöckner
committed
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _, pgettext_lazy
ifaint
committed
from course.constants import ( # noqa
COURSE_ID_REGEX,
EVENT_KIND_REGEX,
EXAM_TICKET_STATE_CHOICES,
FLOW_PERMISSION_CHOICES,
FLOW_RULE_KIND_CHOICES,
FLOW_SESSION_EXPIRATION_MODE_CHOICES,
GRADE_AGGREGATION_STRATEGY_CHOICES,
GRADE_STATE_CHANGE_CHOICES,
GRADING_OPP_ID_REGEX,
PARTICIPATION_PERMISSION_CHOICES,
PARTICIPATION_STATUS_CHOICES,
USER_STATUS_CHOICES,
exam_ticket_states,
flow_permission,
flow_rule_kind,
flow_session_expiration_mode,
grade_aggregation_strategy,
grade_state_change_types,
participation_permission,
participation_status,
from relate.utils import not_none, string_concat
Andreas Klöckner
committed
# {{{ mypy
if TYPE_CHECKING:
from course.content import FlowDesc
from course.page.base import AnswerFeedback
Andreas Klöckner
committed
# }}}
from yamlfield.fields import YAMLField
def validate_course_specific_language(value: str) -> None:
if not value.strip():
# the default value is ""
return
if value not in (
[lang_code for lang_code, lang_descr in settings.LANGUAGES]
+ [settings.LANGUAGE_CODE]):
raise ValidationError(
_("'%s' is currently not supported as a course specific "
"language at this site.") % value)
identifier = models.CharField(max_length=200, unique=True,
help_text=_("A course identifier. Alphanumeric with dashes, "
"no spaces. This is visible in URLs and determines the location "
"on your file system where the course's git repository lives. "
"This should <em>not</em> be changed after the course has been created "
"without also moving the course's git on the server."),
verbose_name=_("Course identifier"),
db_index=True,
validators=[
RegexValidator(
"^"+COURSE_ID_REGEX+"$",
message=_(
"Identifier may only contain letters, "
"numbers, and hyphens ('-').")),
name = models.CharField(
null=True, blank=False,
max_length=200,
verbose_name=_("Course name"),
help_text=_("A human-readable name for the course. "
"(e.g. 'Numerical Methods')"))
number = models.CharField(
null=True, blank=False,
max_length=200,
verbose_name=_("Course number"),
help_text=_("A human-readable course number/ID "
"for the course (e.g. 'CS123')"))
time_period = models.CharField(
null=True, blank=False,
max_length=200,
verbose_name=_("Time Period"),
help_text=_("A human-readable description of the "
"time period for the course (e.g. 'Fall 2014')"))
start_date = models.DateField(
verbose_name=_("Start date"),
null=True, blank=True)
end_date = models.DateField(
verbose_name=_("End date"),
null=True, blank=True)
hidden = models.BooleanField(
default=True,
help_text=_("Is the course only accessible to course staff?"),
verbose_name=_("Only visible to course staff"))
help_text=_("Should the course be listed on the main page?"),
verbose_name=_("Listed on main page"))
accepts_enrollment = models.BooleanField(
Dong Zhuang
committed
default=True,
verbose_name=_("Accepts enrollment"))
git_source = models.CharField(max_length=200, blank=False,
help_text=_("A Git URL from which to pull course updates. "
"<tt>https://github.com/inducer/relate-sample.git</tt> "
"to get some sample content."),
verbose_name=_("git source"))
ssh_private_key = models.TextField(blank=True,
help_text=_("An SSH private key to use for Git authentication. "
"Not needed for the sample URL above."
"You may use <a href='/generate-ssh-key'>this tool</a> to generate "
"a key pair."),
verbose_name=_("SSH private key"))
course_root_path = models.CharField(max_length=200, blank=True,
help_text=_(
"Subdirectory <em>within</em> the git repository to use as "
"course root directory. Not required, and usually blank. "
"Use only if your course content lives in a subdirectory "
"of your git repository. "
"Should not include trailing slash."),
verbose_name=_("Course root in repository"))
course_file = models.CharField(max_length=200,
default="course.yml",
help_text=_("Name of a YAML file in the git repository that "
"contains the root course descriptor."),
verbose_name=_("Course file"))
events_file = models.CharField(max_length=200,
default="events.yml",
help_text=_("Name of a YAML file in the git repository that "
"contains calendar information."),
verbose_name=_("Events file"))
enrollment_approval_required = models.BooleanField(
help_text=_("If set, each enrolling student must be "
"individually approved."),
verbose_name=_("Enrollment approval required"))
preapproval_require_verified_inst_id = models.BooleanField(
default=True,
help_text=_("If set, students cannot get participation "
"preapproval using institutional ID if "
verbose_name=_("Prevent preapproval by institutional ID if not "
"verified?"))
enrollment_required_email_suffix = models.CharField(
max_length=200, blank=True, null=True,
Loading
Loading full blame...