Skip to content
models.py 3.94 KiB
Newer Older
Andreas Klöckner's avatar
Andreas Klöckner committed
from django.db import models
from django.contrib.auth.models import User
from django.utils.timezone import now
from django.core.urlresolvers import reverse
Andreas Klöckner's avatar
Andreas Klöckner committed
class user_status:
    requested = "requested"
    active = "active"

USER_STATUS_CHOICES = (
        (user_status.requested, "Requested"),
        (user_status.active, "Active"),
        )

Andreas Klöckner's avatar
Andreas Klöckner committed
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)


Andreas Klöckner's avatar
Andreas Klöckner committed
class Course(models.Model):
    identifier = models.CharField(max_length=200, unique=True,
            help_text="A URL identifier. Alphanumeric with dashes, "
Andreas Klöckner's avatar
Andreas Klöckner committed
            "no spaces",
            db_index=True)
    git_source = models.CharField(max_length=200, blank=True,
Andreas Klöckner's avatar
Andreas Klöckner committed
            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,
            help_text="An XMPP ID")
Andreas Klöckner's avatar
Andreas Klöckner committed
    active_git_commit_sha = models.CharField(max_length=200, null=True,
            blank=True)
Andreas Klöckner's avatar
Andreas Klöckner committed

    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,))


Andreas Klöckner's avatar
Andreas Klöckner committed
class participation_role:
Andreas Klöckner's avatar
Andreas Klöckner committed
    instructor = "instructor"
    teaching_assistant = "ta"
    student = "student"
    unenrolled = "student"
Andreas Klöckner's avatar
Andreas Klöckner committed
PARTICIPATION_ROLE_CHOICES = (
        (participation_role.instructor, "Instructor"),
        (participation_role.teaching_assistant, "Teaching Assistant"),
        (participation_role.student, "Student"),
        # unenrolled is only used internally
class participation_status:
Andreas Klöckner's avatar
Andreas Klöckner committed
    requested = "requested"
    email_confirmed = "email_confirmed"
    active = "active"
    dropped = "dropped"


Andreas Klöckner's avatar
Andreas Klöckner committed
PARTICIPATION_STATUS_CHOICES = (
        (participation_status.requested, "Requested"),
        (participation_status.email_confirmed, "Email confirmed"),
        (participation_status.active, "Active"),
        (participation_status.dropped, "Dropped"),
Andreas Klöckner's avatar
Andreas Klöckner committed
        )


class Participation(models.Model):
    user = models.ForeignKey(User)
    course = models.ForeignKey(Course)

    enroll_time = models.DateTimeField(default=now)
    role = models.CharField(max_length=50,
Andreas Klöckner's avatar
Andreas Klöckner committed
            choices=PARTICIPATION_ROLE_CHOICES)
Andreas Klöckner's avatar
Andreas Klöckner committed
    status = models.CharField(max_length=50,
Andreas Klöckner's avatar
Andreas Klöckner committed
            choices=PARTICIPATION_STATUS_CHOICES)
Andreas Klöckner's avatar
Andreas Klöckner committed

Andreas Klöckner's avatar
Andreas Klöckner committed
    time_factor = models.DecimalField(
            max_digits=10, decimal_places=2,
            default=1)
Andreas Klöckner's avatar
Andreas Klöckner committed

Andreas Klöckner's avatar
Andreas Klöckner committed
    def __unicode__(self):
        return "%s in %s as %s" % (
                self.user, self.course, self.role)
Andreas Klöckner's avatar
Andreas Klöckner committed

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"


Andreas Klöckner's avatar
Andreas Klöckner committed
class FlowVisit(models.Model):
    participation = models.ForeignKey(Participation)
    active_git_commit_sha = models.CharField(max_length=200)
Andreas Klöckner's avatar
Andreas Klöckner committed
    flow_id = models.CharField(max_length=200)
    start_time = models.DateTimeField(default=now)
Andreas Klöckner's avatar
Andreas Klöckner committed

    state = models.CharField(max_length=50)
class FlowPageVisit(models.Model):
Andreas Klöckner's avatar
Andreas Klöckner committed
    ordinal = models.IntegerField()
    flow_visit = models.ForeignKey(FlowVisit)
Andreas Klöckner's avatar
Andreas Klöckner committed

    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)