diff options
author | prathamesh | 2016-03-02 15:48:39 +0530 |
---|---|---|
committer | prathamesh | 2016-03-02 15:48:39 +0530 |
commit | d9793c01304498d7f59820cf2ab2d7a5483851f8 (patch) | |
tree | e1e2b3fdfb64e9165c56be7115303ea69b14cd17 /yaksh/models.py | |
parent | 3b055ad0ad3232a25408632a020d5e3c284c245b (diff) | |
download | online_test-d9793c01304498d7f59820cf2ab2d7a5483851f8.tar.gz online_test-d9793c01304498d7f59820cf2ab2d7a5483851f8.tar.bz2 online_test-d9793c01304498d7f59820cf2ab2d7a5483851f8.zip |
Course module implemented
Moderator can now create courses. Under his courses he can create quizzes.
Students can enroll for the course. Moderator can approve or reject
enrollment request of the student.
Student can view quizzes only for the enrolled course.
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 67 |
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(), |