summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py8
-rw-r--r--yaksh/templates/yaksh/moderator_dashboard.html5
-rw-r--r--yaksh/templates/yaksh/quizzes_user.html7
-rw-r--r--yaksh/templates/yaksh/view_profile.html1
-rw-r--r--yaksh/views.py8
5 files changed, 21 insertions, 8 deletions
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())
diff --git a/yaksh/templates/yaksh/moderator_dashboard.html b/yaksh/templates/yaksh/moderator_dashboard.html
index 17a4924..c848074 100644
--- a/yaksh/templates/yaksh/moderator_dashboard.html
+++ b/yaksh/templates/yaksh/moderator_dashboard.html
@@ -8,7 +8,10 @@
{% block content %}
-<center><h4>List of quizzes! Click on the given links to have a look at answer papers for a quiz.</h4></center>
+<center><h4 class="pull-left">List of quizzes! Click on the given links to have a look at answer papers for a quiz.</h4></center>
+<a href="{{URL_ROOT}}/exam/toggle_moderator/" class="btn btn-primary pull-right">
+ Switch To Student
+</a>
<table class="table table-bordered">
<th>Courses</th>
<th>Quizzes</th>
diff --git a/yaksh/templates/yaksh/quizzes_user.html b/yaksh/templates/yaksh/quizzes_user.html
index 78cdc48..68044da 100644
--- a/yaksh/templates/yaksh/quizzes_user.html
+++ b/yaksh/templates/yaksh/quizzes_user.html
@@ -7,6 +7,13 @@
<center>{{ msg }}</center>
</div>
{% endif %}
+ {% if user.profile.is_moderator %}
+ <div class="row">
+ <a href="{{URL_ROOT}}/exam/toggle_moderator/" class="btn btn-primary pull-right" style="margin-top: 20px; margin-bottom: 20px;">
+ Switch To Moderator
+ </a>
+ </div>
+ {% endif %}
{% if 'Enrolled Courses' not in title%}
<div class="row well">
<form action="{{ URL_ROOT }}/exam/quizzes/" method="post" id="custom-search-form" class="form-search form-horizontal">
diff --git a/yaksh/templates/yaksh/view_profile.html b/yaksh/templates/yaksh/view_profile.html
index 1b75e6e..ce95226 100644
--- a/yaksh/templates/yaksh/view_profile.html
+++ b/yaksh/templates/yaksh/view_profile.html
@@ -37,5 +37,4 @@
</tr>
</table>
<a class="btn btn-primary pull-right" href="{{ URL_ROOT }}/exam/editprofile/">Edit Profile</a>
- <a class="btn btn-primary pull-left" href="{{ URL_ROOT }}/exam/toggle_moderator/">Toggle Moderator Role</a>
{% endblock %}
diff --git a/yaksh/views.py b/yaksh/views.py
index 7cfb03f..bda2774 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -66,7 +66,7 @@ def my_render_to_response(request, template, context=None, **kwargs):
def is_moderator(user, group_name='moderator'):
"""Check if the user is having moderator rights"""
try:
- group = Group.objects.get(name='moderator')
+ group = Group.objects.get(name=group_name)
return user.profile.is_moderator and user in group.user_set.all()
except Profile.DoesNotExist:
return False
@@ -172,8 +172,10 @@ def quizlist_user(request, enrolled=None, msg=None):
)
title = 'All Courses'
- context = {'user': user, 'courses': courses, 'title': title,
- 'msg': msg}
+ context = {
+ 'user': user, 'courses': courses,
+ 'title': title, 'msg': msg
+ }
return my_render_to_response(request, "yaksh/quizzes_user.html", context)