diff options
author | Prabhu Ramachandran | 2016-03-09 15:19:21 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-03-09 15:19:21 +0530 |
commit | 4874eb1e66c12269fa75849048afd2c9f129d5e3 (patch) | |
tree | 444f167c4bf4516b84e0cfeb6e60e921ae8519f8 /yaksh/models.py | |
parent | 2bff22d61d5d4d6f038c5b368ec437c6bda1dfbe (diff) | |
parent | c974da07d46709d3aa3640ba69c89d1a287ff3c1 (diff) | |
download | online_test-4874eb1e66c12269fa75849048afd2c9f129d5e3.tar.gz online_test-4874eb1e66c12269fa75849048afd2c9f129d5e3.tar.bz2 online_test-4874eb1e66c12269fa75849048afd2c9f129d5e3.zip |
Merge pull request #82 from prathamesh920/courses
Courses
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 8415930..1bbd035 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,66 @@ def get_assignment_dir(instance, filename): ############################################################################### +class Course(models.Model): + """ Course for students""" + 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 enroll(self, was_rejected, *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 reject(self, was_enrolled, *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 is_enrolled(self, user): + return user in self.students.all() + + def is_creator(self, user): + return self.creator == user + + def is_self_enroll(self): + return True if self.enrollment == enrollment_methods[1][0] else False + + def get_quizzes(self): + return self.quiz_set.all() + + def activate(self): + self.active = True + + def deactivate(self): + self.active = False + + def __unicode__(self): + return self.name + + +############################################################################### class Question(models.Model): """Question for a quiz.""" @@ -166,6 +232,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(), |