From 0af47ee9292132ab472e3e0bbae617d77437ff72 Mon Sep 17 00:00:00 2001
From: ankitjavalkar
Date: Fri, 13 Jul 2018 12:58:57 +0530
Subject: Fix bug that changes moderator-student view on every profile save

---
 yaksh/models.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'yaksh')

diff --git a/yaksh/models.py b/yaksh/models.py
index 7e0fbb2..152289f 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1026,7 +1026,10 @@ class Profile(models.Model):
             self.user.groups.remove(group)
 
     def save(self, *args, **kwargs):
-        self._toggle_moderator_group(group_name=MOD_GROUP_NAME)
+        if self.pk is not None:
+            old_profile = Profile.objects.get(pk=self.pk)
+            if old_profile.is_moderator != self.is_moderator:
+                self._toggle_moderator_group(group_name=MOD_GROUP_NAME)
         super(Profile, self).save(*args, **kwargs)
 
     def __str__(self):
-- 
cgit