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.
"""
from django.db import models
from django.contrib.auth.models import User
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 _
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,
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,
from yamlfield.fields import YAMLField
# {{{ facility
class Facility(models.Model):
"""Data about a facility from where content may be accessed."""
ifaint
committed
# Translators: for identifier in Facility class
identifier = models.CharField(max_length=50, unique=True,
help_text= _("Format is lower-case-with-hyphens. "
"Do not use spaces."),
verbose_name = _("Facility ID"))
description = models.CharField(max_length=100,
verbose_name = _("Facility description"))
ifaint
committed
# Translators: plural form of facility
def __unicode__(self):
return self.identifier
class FacilityIPRange(models.Model):
"""Network data about a facility from where content may be accessed."""
facility = models.ForeignKey(Facility, related_name="ip_ranges")
ip_range = models.CharField(
max_length=200,
description = models.CharField(max_length=100,)
class Meta:
def clean(self):
import ipaddr
try:
ipaddr.IPNetwork(self.ip_range)
except Exception as e:
raise ValidationError({"ip_range": str(e)})
# }}}
def get_user_status(user):
try:
return user.user_status
except AttributeError:
ustatus = UserStatus()
ustatus.user = user
ustatus.status = user_status.unconfirmed
ustatus.save()
return ustatus
user = models.OneToOneField(User, db_index=True, related_name="user_status")
status = models.CharField(max_length=50,
choices=USER_STATUS_CHOICES)
sign_in_key = models.CharField(max_length=50,
null=True, unique=True, db_index=True, blank=True)
key_time = models.DateTimeField(default=now)
Andreas Klöckner
committed
editor_mode = models.CharField(max_length=20,
# Translators: the text editor used by participants
Andreas Klöckner
committed
choices=(
Andreas Klöckner
committed
("sublime", "Sublime text"),
("emacs", "Emacs"),
("vim", "Vim"),
),
default="default",
Andreas Klöckner
committed
verbose_name = _("User status")
verbose_name_plural = _("User statuses")
ordering = ("key_time",)
ifaint
committed
return _("User status for %(user)s") % {'user':self.user}
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."),
hidden = models.BooleanField(
default=True,
help_text=_("Is the course only accessible to course staff?"),
help_text=_("Should the course be listed on the main page?"),
accepts_enrollment = models.BooleanField(
default=True, verbose_name = _('Accepts enrollment'))
valid = models.BooleanField(
default=True,
help_text=_("Whether the course content has passed validation."),
verbose_name = _('Valid'))
git_source = models.CharField(max_length=200, blank=True,
help_text=_("A Git URL from which to pull course updates. "
"to get some sample content."),
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."),
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."),
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."),
enrollment_approval_required = models.BooleanField(
help_text=_("If set, each enrolling student must be "
"individually approved."),
verbose_name = _('Enrollment approval required'))
enrollment_required_email_suffix = models.CharField(
max_length=200, blank=True, null=True,
help_text=_("Enrollee's email addresses must end in the "
"specified suffix, such as '@illinois.edu'."),
verbose_name = _('Enrollment required email suffix'))
from_email = models.EmailField(
help_text=_("This email address will be used in the 'From' line "
Loading
Loading full blame...