summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authoradityacp2016-04-21 18:57:28 +0530
committeradityacp2016-04-26 19:22:05 +0530
commitfa11260fdbe76f377909483d9c482ecf72ab3364 (patch)
tree730db1ddc2867ecd543d70ab65bcee1971066c54 /yaksh/models.py
parentc2e8c3ff4e07de717f74c0a6d9199c317452bf43 (diff)
downloadonline_test-fa11260fdbe76f377909483d9c482ecf72ab3364.tar.gz
online_test-fa11260fdbe76f377909483d9c482ecf72ab3364.tar.bz2
online_test-fa11260fdbe76f377909483d9c482ecf72ab3364.zip
changes in add teachers as per comments
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py24
1 files changed, 21 insertions, 3 deletions
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