summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2016-07-08 07:57:40 -0500
committerGitHub2016-07-08 07:57:40 -0500
commit7564d453228cfebf4709cbbd19609f0614b6b9bc (patch)
tree55818b1927be1d927b469bdc937c561f6c3145e2 /yaksh/views.py
parent67f77a6a05ed722609ec2fc74e2ba10751c70e08 (diff)
parent2986a8a92b0548b3e7e960aea1c175bb4eddac11 (diff)
downloadonline_test-7564d453228cfebf4709cbbd19609f0614b6b9bc.tar.gz
online_test-7564d453228cfebf4709cbbd19609f0614b6b9bc.tar.bz2
online_test-7564d453228cfebf4709cbbd19609f0614b6b9bc.zip
Merge pull request #104 from ankitjavalkar/view-tests
Add tests for views
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py49
1 files changed, 17 insertions, 32 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index e2ff84f..56746b0 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -7,6 +7,7 @@ from datetime import datetime
import collections
import csv
from django.http import HttpResponse
+from django.core.urlresolvers import reverse
from django.contrib.auth import login, logout, authenticate
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
@@ -22,12 +23,13 @@ from taggit.models import Tag
from itertools import chain
import json
# Local imports.
-from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course
-from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase
+from yaksh.models import get_model_class, Quiz, Question, QuestionPaper,\
+ QuestionSet, Course, Profile, Answer, AnswerPaper, User, TestCase,\
+ has_profile
from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\
- QuestionForm, RandomQuestionForm,\
- QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm,\
- get_object_form
+ QuestionForm, RandomQuestionForm,\
+ QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm,\
+ get_object_form
from yaksh.xmlrpc_clients import code_server
from settings import URL_ROOT
from yaksh.models import AssignmentUpload
@@ -67,13 +69,9 @@ def get_user_dir(user):
def is_moderator(user):
"""Check if the user is having moderator rights"""
- if user.groups.filter(name='moderator').count() == 1:
+ if user.groups.filter(name='moderator').exists():
return True
-def has_profile(user):
- """ check if user has profile """
- return True if hasattr(user, 'profile') else False
-
def add_to_group(users):
""" add users to moderator group """
group = Group.objects.get(name="moderator")
@@ -221,7 +219,6 @@ def edit_question(request, question_id=None):
def add_quiz(request, quiz_id=None):
"""To add a new quiz in the database.
Create a new quiz and store it."""
-
user = request.user
ci = RequestContext(request)
if not is_moderator(user):
@@ -232,7 +229,7 @@ def add_quiz(request, quiz_id=None):
form = QuizForm(request.POST, user=user)
if form.is_valid():
form.save()
- return my_redirect("/exam/manage/designquestionpaper")
+ return my_redirect(reverse('yaksh:design_questionpaper'))
else:
quiz = Quiz.objects.get(id=quiz_id)
form = QuizForm(request.POST, user=user, instance=quiz)
@@ -240,10 +237,6 @@ def add_quiz(request, quiz_id=None):
form.save()
context["quiz_id"] = quiz_id
return my_redirect("/exam/manage/")
-
- context["form"] = form
- return my_render_to_response('yaksh/add_quiz.html', context,
- context_instance=ci)
else:
if quiz_id is None:
form = QuizForm(user=user)
@@ -618,7 +611,10 @@ def enroll_request(request, course_id):
ci = RequestContext(request)
course = get_object_or_404(Course, pk=course_id)
course.request(user)
- return my_redirect('/exam/manage/')
+ if is_moderator(user):
+ return my_redirect('/exam/manage/')
+ else:
+ return my_redirect('/exam/quizzes/')
@login_required
@@ -629,7 +625,10 @@ def self_enroll(request, course_id):
if course.is_self_enroll():
was_rejected = False
course.enroll(was_rejected, user)
- return my_redirect('/exam/manage/')
+ if is_moderator(user):
+ return my_redirect('/exam/manage/')
+ else:
+ return my_redirect('/exam/quizzes/')
@login_required
@@ -794,20 +793,6 @@ def monitor(request, questionpaper_id=None):
context_instance=ci)
-@login_required
-def show_all_users(request):
- """Shows all the users who have taken various exams/quiz."""
-
- user = request.user
- if not user.is_authenticated() or not is_moderator(user):
- raise Http404('You are not allowed to view this page !')
- user = User.objects.filter(username__contains="")
- questionpaper = AnswerPaper.objects.all()
- context = {'question': questionpaper}
- return my_render_to_response('yaksh/showusers.html', context,
- context_instance=RequestContext(request))
-
-
@csrf_exempt
def ajax_questions_filter(request):
"""Ajax call made when filtering displayed questions."""