summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 8415930..d6fe972 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -40,6 +40,12 @@ question_types = (
("code", "Code"),
("upload", "Assignment Upload"),
)
+
+enrollment_methods = (
+ ("default", "Enroll Request"),
+ ("open", "Open Course"),
+ )
+
attempts = [(i, i) for i in range(1, 6)]
attempts.append((-1, 'Infinite'))
days_between_attempts = ((j, j) for j in range(401))
@@ -55,6 +61,65 @@ def get_assignment_dir(instance, filename):
###############################################################################
+class Course(models.Model):
+ name = models.CharField(max_length=128)
+ enrollment = models.CharField(max_length=32, choices=enrollment_methods)
+ active = models.BooleanField(default=True)
+ creator = models.ForeignKey(User, related_name='creator')
+ students = models.ManyToManyField(User, related_name='students')
+ requests = models.ManyToManyField(User, related_name='requests')
+ rejected = models.ManyToManyField(User, related_name='rejected')
+ created_on = models.DateTimeField(default=datetime.datetime.now())
+
+ def request(self, *users):
+ self.requests.add(*users)
+
+ def get_requests(self):
+ return self.requests.all()
+
+ def reject(self, was_enrolled=False, *users):
+ self.rejected.add(*users)
+ if not was_enrolled:
+ self.requests.remove(*users)
+ else:
+ self.students.remove(*users)
+
+ def get_rejected(self):
+ return self.rejected.all()
+
+ def enroll(self, was_rejected=False, *users):
+ self.students.add(*users)
+ if not was_rejected:
+ self.requests.remove(*users)
+ else:
+ self.rejected.remove(*users)
+
+ def get_enrolled(self):
+ return self.students.all()
+
+ def is_enrolled(self, user_id):
+ return self.students.filter(id=user_id).exists()
+
+ def is_creator(self, user):
+ return self.creator == user
+
+ def get_quizzes(self):
+ return self.quiz_set.all()
+
+ def activate(self):
+ self.active = True
+
+ def deactivate(self):
+ self.active = False
+
+ def is_self_enroll(self):
+ return True if self.enrollment == 'open' else False
+
+ def __unicode__(self):
+ return self.name
+
+
+###############################################################################
class Question(models.Model):
"""Question for a quiz."""
@@ -166,6 +231,8 @@ class Quiz(models.Model):
as the "examination" event.
"""
+ course = models.ForeignKey(Course)
+
# The start date of the quiz.
start_date_time = models.DateTimeField("Start Date and Time of the quiz",
default=datetime.datetime.now(),