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.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,
exam_ticket_states, EXAM_TICKET_STATE_CHOICES,
from yamlfield.fields import YAMLField
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(settings.AUTH_USER_MODEL, db_index=True,
related_name="user_status",
verbose_name=_('User ID'), on_delete=models.CASCADE)
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,
help_text=_("Which key bindings you prefer when editing "
"larger amounts of text or code. "
"(If you do not understand what this means, "
"leave it as 'Default'.)"),
Andreas Klöckner
committed
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. "
"This should *not* be changed after the course has been created "
"without also moving the course's git on the server."),
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'))
help_text=_("Should the course be listed on the main page?"),
accepts_enrollment = models.BooleanField(
Dong Zhuang
committed
default=True,
verbose_name=_('Accepts enrollment'))
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."
"You may use <a href='/generate-ssh-key'>this tool</a> to generate "
"a key pair."),
course_root_path = models.CharField(max_length=200, blank=True,
help_text=_(
'Subdirectory *within* 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."),
events_file = models.CharField(max_length=200,
default="events.yml",
help_text=_("Name of a YAML file in the git repository that "
Loading
Loading full blame...