From 5d92e6fac7901c9829a759aec539e603dfb66038 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 26 Apr 2016 19:00:01 +0530 Subject: rebase changes --- yaksh/models.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 9b92791..65b4dc0 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -71,6 +71,8 @@ class Course(models.Model): requests = models.ManyToManyField(User, related_name='requests') rejected = models.ManyToManyField(User, related_name='rejected') created_on = models.DateTimeField(auto_now_add=True) + teachers = models.ManyToManyField(User, related_name='teachers') + def request(self, *users): self.requests.add(*users) @@ -116,6 +118,9 @@ class Course(models.Model): def deactivate(self): self.active = False + def add_teachers(self, *users): + self.teachers.add(*users) + def __unicode__(self): return self.name -- cgit From fa11260fdbe76f377909483d9c482ecf72ab3364 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 21 Apr 2016 18:57:28 +0530 Subject: changes in add teachers as per comments --- yaksh/models.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 65b4dc0..6db1298 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -4,7 +4,7 @@ from random import sample, shuffle from itertools import islice, cycle from collections import Counter from django.db import models -from django.contrib.auth.models import User +from django.contrib.auth.models import User, Group from taggit.managers import TaggableManager @@ -23,6 +23,14 @@ class Profile(models.Model): department = models.CharField(max_length=64) position = models.CharField(max_length=64) + def is_moderator(self, user): + return True if user.groups.filter(name='moderator').exists() else False + + def _add_to_group(self, user): + group = Group.objects.get(name="moderator") + user.groups.add(group) + user.profile.position = "Faculty" + user.profile.save() languages = ( ("python", "Python"), @@ -118,8 +126,18 @@ class Course(models.Model): def deactivate(self): self.active = False - def add_teachers(self, *users): - self.teachers.add(*users) + def add_teachers(self, *teachers): + added_teachers = list() + rejected_teachers = list() + for teacher in teachers: + if hasattr(teacher, 'profile'): + if not teacher.profile.is_moderator(teacher): + teacher.profile._add_to_group(teacher) + self.teachers.add(teacher) + added_teachers.append(teacher) + else: + rejected_teachers.append(teacher) + return added_teachers, rejected_teachers def __unicode__(self): return self.name -- cgit From 6b09383890b8367628124a854810326d7bbac7c4 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 27 Apr 2016 16:42:32 +0530 Subject: changes after comments --- yaksh/models.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 6db1298..bb85085 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -24,13 +24,11 @@ class Profile(models.Model): position = models.CharField(max_length=64) def is_moderator(self, user): - return True if user.groups.filter(name='moderator').exists() else False + return user.groups.filter(name='moderator').exists() def _add_to_group(self, user): group = Group.objects.get(name="moderator") user.groups.add(group) - user.profile.position = "Faculty" - user.profile.save() languages = ( ("python", "Python"), @@ -139,6 +137,12 @@ class Course(models.Model): rejected_teachers.append(teacher) return added_teachers, rejected_teachers + def get_teachers(self): + return self.teachers.all() + + def remove_teachers(self, *teachers): + self.teachers.remove(*teachers) + def __unicode__(self): return self.name -- cgit From 3438ca95172897b594c216967d51cf5771d75f73 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 28 Apr 2016 12:22:30 +0530 Subject: further commented changes --- yaksh/models.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index bb85085..cb9582f 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -112,6 +112,9 @@ class Course(models.Model): def is_creator(self, user): return self.creator == user + def is_teacher(self, user): + return True if user in self.teachers.all() else False + def is_self_enroll(self): return True if self.enrollment == enrollment_methods[1][0] else False -- cgit From d2affe68e84da54dc99d9876ab359ad448aa6828 Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 29 Apr 2016 14:40:50 +0530 Subject: changes for adding teachers --- yaksh/models.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index cb9582f..a4ea6c3 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -4,7 +4,7 @@ from random import sample, shuffle from itertools import islice, cycle from collections import Counter from django.db import models -from django.contrib.auth.models import User, Group +from django.contrib.auth.models import User from taggit.managers import TaggableManager @@ -23,13 +23,6 @@ class Profile(models.Model): department = models.CharField(max_length=64) position = models.CharField(max_length=64) - def is_moderator(self, user): - return user.groups.filter(name='moderator').exists() - - def _add_to_group(self, user): - group = Group.objects.get(name="moderator") - user.groups.add(group) - languages = ( ("python", "Python"), ("bash", "Bash"), @@ -128,17 +121,7 @@ class Course(models.Model): self.active = False def add_teachers(self, *teachers): - added_teachers = list() - rejected_teachers = list() - for teacher in teachers: - if hasattr(teacher, 'profile'): - if not teacher.profile.is_moderator(teacher): - teacher.profile._add_to_group(teacher) - self.teachers.add(teacher) - added_teachers.append(teacher) - else: - rejected_teachers.append(teacher) - return added_teachers, rejected_teachers + self.teachers.add(*teachers) def get_teachers(self): return self.teachers.all() -- cgit