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
Dong Zhuang
committed
from django.utils.translation import (
ugettext_lazy as _ ,
pgettext_lazy,
ugettext_noop,
string_concat,
ugettext,
)
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. "
Dong Zhuang
committed
"Do not use spaces.",
verbose_name = "Facility ID")
description = models.CharField(max_length=100,
verbose_name = "Facility description")
Dong Zhuang
committed
verbose_name = "Facility"
verbose_name_plural = "Facilities"
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,
Dong Zhuang
committed
verbose_name="IP range")
Dong Zhuang
committed
description = models.CharField(max_length=100,
verbose_name = 'Ip range description')
Dong Zhuang
committed
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
Dong Zhuang
committed
user = models.OneToOneField(User, db_index=True, related_name="user_status",
verbose_name = 'User ID')
Dong Zhuang
committed
choices=USER_STATUS_CHOICES,
verbose_name = 'User status')
sign_in_key = models.CharField(max_length=50,
Dong Zhuang
committed
help_text="NEED HELP TEXT",
null=True, unique=True, db_index=True, blank=True,
verbose_name = 'Sign in key')
key_time = models.DateTimeField(default=now,
help_text="NEED HELP TEXT",
verbose_name = 'Key time')
Andreas Klöckner
committed
editor_mode = models.CharField(max_length=20,
choices=(
("default", "Default"),
("sublime", "Sublime text"),
("emacs", "Emacs"),
("vim", "Vim"),
),
Dong Zhuang
committed
default="default",
# Translators: the text editor used by participants
verbose_name = "Editor mode")
Andreas Klöckner
committed
Dong Zhuang
committed
verbose_name = "User status"
verbose_name_plural = "User statuses"
ordering = ("key_time",)
Dong Zhuang
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.",
Dong Zhuang
committed
verbose_name = 'Course ID',
hidden = models.BooleanField(
default=True,
Dong Zhuang
committed
help_text="Is the course only accessible to course staff?",
verbose_name = 'Hidden to student')
Dong Zhuang
committed
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')
valid = models.BooleanField(
default=True,
Dong Zhuang
committed
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. "
"If you're just starting out, enter "
Dong Zhuang
committed
"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. "
Dong Zhuang
committed
"Not needed for the sample URL above.",
verbose_name = 'SSH private key')
course_file = models.CharField(max_length=200,
default="course.yml",
help_text="Name of a YAML file in the git repository that contains "
Dong Zhuang
committed
"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 "
Dong Zhuang
committed
"calendar information.",
verbose_name = 'Events file')
enrollment_approval_required = models.BooleanField(
Loading
Loading full blame...