Skip to content
models.py 53.2 KiB
Newer Older
# -*- coding: utf-8 -*-

from __future__ import division

__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.
"""

import six

Andreas Klöckner's avatar
Andreas Klöckner committed
from django.db import models
from django.utils.timezone import now
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.utils.translation import (
        ugettext_lazy as _, pgettext_lazy, string_concat)
Andreas Klöckner's avatar
Andreas Klöckner committed
from django.core.validators import RegexValidator
from django.conf import settings

from course.constants import (  # noqa
        user_status, USER_STATUS_CHOICES,
        participation_role, PARTICIPATION_ROLE_CHOICES,
        participation_status, PARTICIPATION_STATUS_CHOICES,
        flow_permission, FLOW_PERMISSION_CHOICES,
Andreas Klöckner's avatar
Andreas Klöckner committed
        flow_session_expiration_mode, FLOW_SESSION_EXPIRATION_MODE_CHOICES,
        grade_aggregation_strategy, GRADE_AGGREGATION_STRATEGY_CHOICES,
        grade_state_change_types, GRADE_STATE_CHANGE_CHOICES,
        flow_rule_kind, FLOW_RULE_KIND_CHOICES,
        exam_ticket_states, EXAM_TICKET_STATE_CHOICES,
Andreas Klöckner's avatar
Andreas Klöckner committed

        COURSE_ID_REGEX
from jsonfield import JSONField
from yamlfield.fields import YAMLField
Andreas Klöckner's avatar
Andreas Klöckner committed

Andreas Klöckner's avatar
Andreas Klöckner committed

Andreas Klöckner's avatar
Andreas Klöckner committed

Andreas Klöckner's avatar
Andreas Klöckner committed
class Course(models.Model):
    identifier = models.CharField(max_length=200, unique=True,
ifaint's avatar
ifaint committed
            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."),
ifaint's avatar
ifaint committed
            verbose_name=_('Course identifier'),
Andreas Klöckner's avatar
Andreas Klöckner committed
            db_index=True,
            validators=[
                RegexValidator(
                    "^"+COURSE_ID_REGEX+"$",
                    message=_(
                        "Identifier may only contain letters, "
                        "numbers, and hypens ('-').")),
                    ]
            )
    name = models.CharField(
            null=True, blank=False,
            max_length=200,
            help_text=_("A human-readable name for the course. "
                "(e.g. 'Numerical Methods')"))
    number = models.CharField(
            null=True, blank=False,
            max_length=200,
            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,
            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'))
    listed = models.BooleanField(
            default=True,
            help_text=_("Should the course be listed on the main page?"),
ifaint's avatar
ifaint committed
            verbose_name=_('Listed on main page'))
    accepts_enrollment = models.BooleanField(
            verbose_name=_('Accepts enrollment'))
    git_source = models.CharField(max_length=200, blank=True,
ifaint's avatar
ifaint committed
            help_text=_("A Git URL from which to pull course updates. "
            "If you're just starting out, enter "
Andreas Klöckner's avatar
Andreas Klöckner committed
            "<tt>git://github.com/inducer/relate-sample</tt> "
            "to get some sample content."),
ifaint's avatar
ifaint committed
            verbose_name=_('git source'))
    ssh_private_key = models.TextField(blank=True,
ifaint's avatar
ifaint committed
            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."),
ifaint's avatar
ifaint committed
            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."),
ifaint's avatar
ifaint committed
            verbose_name=_('Course file'))
Andreas Klöckner's avatar
Andreas Klöckner committed
    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."),
ifaint's avatar
ifaint committed
            verbose_name=_('Events file'))
    enrollment_approval_required = models.BooleanField(
            default=False,
ifaint's avatar
ifaint committed
            help_text=_("If set, each enrolling student must be "
            "individually approved."),
ifaint's avatar
ifaint committed
            verbose_name=_('Enrollment approval required'))
    preapproval_require_verified_inst_id = models.BooleanField(
            default=True,
            help_text=_("If set, students cannot get particiaption "
                        "preapproval using institutional ID if "
                        "institutional ID they provided are not "
                        "verified."),
            verbose_name=_('None preapproval by institutional ID if not '
                           'verified?'))
    enrollment_required_email_suffix = models.CharField(
            max_length=200, blank=True, null=True,
ifaint's avatar
ifaint committed
            help_text=_("Enrollee's email addresses must end in the "
            "specified suffix, such as '@illinois.edu'."),
ifaint's avatar
ifaint committed
            verbose_name=_('Enrollment required email suffix'))
    from_email = models.EmailField(
            # Translators: replace "RELATE" with the brand name of your
            # website if necessary.
ifaint's avatar
ifaint committed
            help_text=_("This email address will be used in the 'From' line "
            "of automated emails sent by RELATE."),
ifaint's avatar
ifaint committed
            verbose_name=_('From email'))

    notify_email = models.EmailField(
ifaint's avatar
ifaint committed
            help_text=_("This email address will receive "
            "notifications about the course."),
ifaint's avatar
ifaint committed
            verbose_name=_('Notify email'))

    # {{{ XMPP

    course_xmpp_id = models.CharField(max_length=200, blank=True, null=True,
            help_text=_("(Required only if the instant message feature is "
            "desired.) The Jabber/XMPP ID (JID) the course will use to sign "
            "in to an XMPP server."),
ifaint's avatar
ifaint committed
            verbose_name=_('Course xmpp ID'))
    course_xmpp_password = models.CharField(max_length=200, blank=True, null=True,
            help_text=_("(Required only if the instant message feature is "
            "desired.) The password to go with the JID above."),
ifaint's avatar
ifaint committed
            verbose_name=_('Course xmpp password'))

    recipient_xmpp_id = models.CharField(max_length=200, blank=True, null=True,
            help_text=_("(Required only if the instant message feature is "
            "desired.) The JID to which instant messages will be sent."),
ifaint's avatar
ifaint committed
            verbose_name=_('Recipient xmpp ID'))
    active_git_commit_sha = models.CharField(max_length=200, null=False,
ifaint's avatar
ifaint committed
            blank=False,
ifaint's avatar
ifaint committed
            verbose_name=_('Active git commit SHA'))
Andreas Klöckner's avatar
Andreas Klöckner committed

Loading
Loading full blame...