diff options
author | ankitjavalkar | 2018-05-16 17:53:55 +0530 |
---|---|---|
committer | ankitjavalkar | 2018-07-13 13:00:35 +0530 |
commit | 26ca38c6243eaa1d94bca68481eb60b2276ab7b2 (patch) | |
tree | 0e8a60727b9a951bd85780275bd742c635d27f82 /yaksh/models.py | |
parent | 661c9d82bb680e745cc6b498131a0793b954c436 (diff) | |
download | online_test-26ca38c6243eaa1d94bca68481eb60b2276ab7b2.tar.gz online_test-26ca38c6243eaa1d94bca68481eb60b2276ab7b2.tar.bz2 online_test-26ca38c6243eaa1d94bca68481eb60b2276ab7b2.zip |
Allow moderator to switch between student and moderator roles
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 1eca721..1199a92 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -8,7 +8,7 @@ from ruamel.yaml.comments import CommentedMap from random import sample 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 django.contrib.contenttypes.models import ContentType from taggit.managers import TaggableManager from django.utils import timezone @@ -982,6 +982,7 @@ class Profile(models.Model): institute = models.CharField(max_length=128) department = models.CharField(max_length=64) position = models.CharField(max_length=64) + is_moderator = models.BooleanField(default=False) timezone = models.CharField( max_length=64, default=pytz.utc.zone, @@ -1000,6 +1001,15 @@ class Profile(models.Model): os.chmod(user_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) return user_dir + def _add_to_moderator_group(self, group_name='moderator'): + if self.is_moderator: + group = Group.objects.get(name=group_name) + self.user.groups.add(group) + + def save(self, *args, **kwargs): + super(Profile, self).save(*args, **kwargs) + self._add_to_moderator_group() + def __str__(self): return '%s' % (self.user.get_full_name()) |