From 69a07a92309105b289f4d08957729bda68727bf2 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 5 Jul 2018 17:46:00 +0530 Subject: - Add buttons to Moderator and Student templates - Modify _add_to_moderator function to _toggle_moderator_function in order to allow addition and removal of moderator group link --- yaksh/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 1199a92..e9d4947 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1001,14 +1001,16 @@ 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'): + def _toggle_moderator_group(self, group_name='moderator'): + group = Group.objects.get(name=group_name) if self.is_moderator: - group = Group.objects.get(name=group_name) self.user.groups.add(group) + else: + self.user.groups.remove(group) def save(self, *args, **kwargs): + self._toggle_moderator_group() super(Profile, self).save(*args, **kwargs) - self._add_to_moderator_group() def __str__(self): return '%s' % (self.user.get_full_name()) -- cgit