From b58a0b9831d8e6434362f776c89076c2d84e9b26 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 7 Mar 2016 15:29:36 +0530 Subject: Added tests for Course model --- yaksh/models.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index d6fe972..46fb9a3 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -62,6 +62,7 @@ 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) @@ -77,17 +78,7 @@ class Course(models.Model): 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): + def enroll(self, was_rejected, *users): self.students.add(*users) if not was_rejected: self.requests.remove(*users) @@ -97,12 +88,25 @@ class Course(models.Model): 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_id): return self.students.filter(id=user_id).exists() 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() @@ -112,9 +116,6 @@ class Course(models.Model): 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 -- cgit