Newer
Older
from django.db import models
from django.contrib.auth.models import User
from django.utils.timezone import now
from django.core.urlresolvers import reverse
class user_status:
requested = "requested"
active = "active"
USER_STATUS_CHOICES = (
(user_status.requested, "Requested"),
(user_status.active, "Active"),
)
class UserStatus(models.Model):
user = models.OneToOneField(User)
status = models.CharField(max_length=50,
choices=USER_STATUS_CHOICES)
registration_key = models.CharField(max_length=50,
null=True, unique=True, db_index=True)
identifier = models.CharField(max_length=200, unique=True,
help_text="A URL identifier. Alphanumeric with dashes, "
db_index=True)
git_source = models.CharField(max_length=200, blank=True,
help_text="A Git URL from which to pull course updates")
ssh_private_key = models.CharField(max_length=2000, blank=True,
help_text="An SSH private key to use for Git authentication")
xmpp_id = models.CharField(max_length=200, blank=True,
help_text="An XMPP ID")
xmpp_password = models.CharField(max_length=200, blank=True)
active_git_commit_sha = models.CharField(max_length=200, null=False,
blank=False)
participants = models.ManyToManyField(User,
through='Participation')
def __unicode__(self):
return self.identifier
def get_absolute_url(self):
return reverse("course.views.course_page", args=(self.identifier,))
instructor = "instructor"
teaching_assistant = "ta"
student = "student"
PARTICIPATION_ROLE_CHOICES = (
(participation_role.instructor, "Instructor"),
(participation_role.teaching_assistant, "Teaching Assistant"),
(participation_role.student, "Student"),
requested = "requested"
email_confirmed = "email_confirmed"
active = "active"
dropped = "dropped"
(participation_status.requested, "Requested"),
(participation_status.email_confirmed, "Email confirmed"),
(participation_status.active, "Active"),
(participation_status.dropped, "Dropped"),
)
class Participation(models.Model):
user = models.ForeignKey(User)
course = models.ForeignKey(Course)
enroll_time = models.DateTimeField(default=now)
role = models.CharField(max_length=50,
time_factor = models.DecimalField(
max_digits=10, decimal_places=2,
default=1)
preview_git_commit_sha = models.CharField(max_length=200, null=True,
blank=True)
def __unicode__(self):
return "%s in %s as %s" % (
self.user, self.course, self.role)
class InstantFlowRequest(models.Model):
course = models.ForeignKey(Course)
flow_id = models.CharField(max_length=200)
start_time = models.DateTimeField(default=now)
end_time = models.DateTimeField()
class flow_visit_state:
in_progress = "in_progress"
expired = "expired"
completed = "completed"
participation = models.ForeignKey(Participation)
active_git_commit_sha = models.CharField(max_length=200)
start_time = models.DateTimeField(default=now)
state = models.CharField(max_length=50)
flow_visit = models.ForeignKey(FlowVisit)
page_id = models.CharField(max_length=200)
visit_time = models.DateTimeField(default=now)
answer_time = models.DateTimeField(default=now)
answer_value = models.CharField(max_length=200)
points = models.DecimalField(max_digits=10, decimal_places=2)