diff options
author | ankitjavalkar | 2019-01-28 11:03:39 +0530 |
---|---|---|
committer | GitHub | 2019-01-28 11:03:39 +0530 |
commit | 53e43a65f0b47557da035597f37b4ee9a9d5e290 (patch) | |
tree | 32a6095973f3bc4f198942fd416da870847058d8 /yaksh | |
parent | 310d3813f58d292b54e42fb43f4554cbe5c944ce (diff) | |
parent | 7f91d11b37aaeb5a673f623d21ff2390983e0f8c (diff) | |
download | online_test-53e43a65f0b47557da035597f37b4ee9a9d5e290.tar.gz online_test-53e43a65f0b47557da035597f37b4ee9a9d5e290.tar.bz2 online_test-53e43a65f0b47557da035597f37b4ee9a9d5e290.zip |
Merge pull request #551 from ankitjavalkar/remove-mod-from-teacher
Remove user as teacher of any course if is_moderator is set to False
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 5 | ||||
-rw-r--r-- | yaksh/templates/yaksh/regrade.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/showquestions.html | 2 | ||||
-rw-r--r-- | yaksh/test_models.py | 38 |
4 files changed, 41 insertions, 6 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 480a111..427b584 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1096,12 +1096,17 @@ class Profile(models.Model): os.chmod(user_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) return user_dir + def get_moderated_courses(self): + return Course.objects.filter(teachers=self.user) + def _toggle_moderator_group(self, group_name): group = Group.objects.get(name=group_name) if self.is_moderator: self.user.groups.add(group) else: self.user.groups.remove(group) + for course in self.get_moderated_courses(): + course.remove_teachers(self.user) def save(self, *args, **kwargs): if self.pk is not None: diff --git a/yaksh/templates/yaksh/regrade.html b/yaksh/templates/yaksh/regrade.html index d119480..c70e470 100644 --- a/yaksh/templates/yaksh/regrade.html +++ b/yaksh/templates/yaksh/regrade.html @@ -10,7 +10,7 @@ <a href="#intro" data-toggle="pill" class="nav-link active" role="tab" aria-controls="intro" aria-selected="true" id="introtab"> Intro </a> <a href="#questions" data-toggle="pill" class="nav-link" role="tab" aria-controls="questions" aria-selected="false" id="questionstab"> Question-wise regrade </a> <a href="#quizzes" data-toggle="pill" class="nav-link" role="tab" aria-controls="quizzes" aria-selected="false" id="quizzestab"> Quiz-wise regrade </a> - <li><a href="#users" data-toggle="pill" class="nav-link" role="tab" aria-controls="users" aria-selected="false" id="userstab"> User-wise regrade </a> + <a href="#users" data-toggle="pill" class="nav-link" role="tab" aria-controls="users" aria-selected="false" id="userstab"> User-wise regrade </a> </div> </div><!--end of siddebar--> <a href="#sidebar" data-toggle="collapse" id="sidebaricon"><i class="fa fa-navicon fa-lg"></i></a> diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html index 915dcda..e146878 100644 --- a/yaksh/templates/yaksh/showquestions.html +++ b/yaksh/templates/yaksh/showquestions.html @@ -23,7 +23,7 @@ <div class="yakshwell tab-content"> <!-- Upload Questions --> - <div id="updown" class="card col-md-5 tab-pane fade" role="tabpanel" aria-labelledby="updownbar"> + <div id="updown" class="card col-md-12 tab-pane fade" role="tabpanel" aria-labelledby="updownbar"> <div class="alert alert-info" role="alert"> <p>You can upload question files the following ways - <li><b><u>Yaml File</u></b> diff --git a/yaksh/test_models.py b/yaksh/test_models.py index c9cb953..aea47de 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -285,19 +285,49 @@ class LearningUnitTestCases(unittest.TestCase): class ProfileTestCases(unittest.TestCase): def setUp(self): - self.user1 = User.objects.get(username='creator') - self.profile = Profile.objects.get(user=self.user1) - self.user2 = User.objects.get(username='demo_user3') + self.creator = User.objects.get(username='creator') + self.profile = Profile.objects.get(user=self.creator) + self.teacher = User.objects.create_user(username='teacher_profile', + password='teacher_profile', + email='teacher_profile@test.com') + Profile.objects.create( + user=self.teacher, roll_number=123, institute='IIT', + is_moderator=True, department='Chemical', position='Teacher' + ) + self.course = Course.objects.create( + name="Course For ProfileTestCase", + enrollment="Open Course", + creator=self.creator, + start_enroll_time=datetime( + 2015, 10, 9, 10, 8, 15, 0, + tzinfo=pytz.utc + ), + end_enroll_time=datetime( + 2015, 11, 9, 10, 8, 15, 0, + tzinfo=pytz.utc + ), + ) + self.course.add_teachers(self.teacher) def test_user_profile(self): """ Test user profile""" - self.assertEqual(self.user1.username, 'creator') + self.assertEqual(self.creator.username, 'creator') self.assertEqual(self.profile.user.username, 'creator') self.assertEqual(int(self.profile.roll_number), 1) self.assertEqual(self.profile.institute, 'IIT') self.assertEqual(self.profile.department, 'Chemical') self.assertEqual(self.profile.position, 'Student') + def test_profile_is_moderator_removes_teacher(self): + teacher_profile = self.teacher.profile + teacher_profile.is_moderator = False + teacher_profile.save() + self.assertNotIn(self.teacher, self.course.teachers.all()) + + def tearDown(self): + self.teacher.profile.delete() + self.teacher.delete() + self.course.delete() ############################################################################### class QuestionTestCases(unittest.TestCase): |