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 _, pgettext_lazy, string_concat)
ifaint
committed
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."""
identifier = models.CharField(max_length=50, unique=True,
help_text=_("Format is lower-case-with-hyphens. "
"Do not use spaces."),
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,
ifaint
committed
description = models.CharField(max_length=100,
verbose_name = _("Facility IP range")
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",
ifaint
committed
choices=USER_STATUS_CHOICES,
sign_in_key = models.CharField(max_length=50,
help_text=_("The sign in token sent out in email."),
ifaint
committed
null=True, unique=True, db_index=True, blank=True,
# Translators: the sign in token of the user.
verbose_name=_('Sign in key'))
ifaint
committed
key_time = models.DateTimeField(default=now,
help_text=_("The time stamp of the sign in token."),
# Translators: the time when the token is sent out.
verbose_name=_('Key time'))
ifaint
committed
Andreas Klöckner
committed
editor_mode = models.CharField(max_length=20,
choices=(
Andreas Klöckner
committed
("sublime", "Sublime text"),
("emacs", "Emacs"),
("vim", "Vim"),
),
default="default",
ifaint
committed
# Translators: the text editor used by participants
Andreas Klöckner
committed
verbose_name = _("User status")
verbose_name_plural = _("User statuses")
ordering = ("key_time",)
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(
Dong Zhuang
committed
default=True,
verbose_name=_('Accepts enrollment'))
valid = models.BooleanField(
default=True,
help_text=_("Whether the course content has passed validation."),
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 "
Loading
Loading full blame...