From 762d5ed41922150df1f91ef1835ea03a192f7d28 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 10 May 2016 17:46:52 +0530 Subject: added view functions for godmode, usermode and test_questions --- yaksh/views.py | 87 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 25 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 2a3adbf..019b631 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -6,7 +6,7 @@ from os.path import dirname, pardir, abspath, join, exists from datetime import datetime import collections import csv -from django.http import HttpResponse +from django.http import HttpResponse, HttpRequest 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 @@ -123,7 +123,7 @@ def quizlist_user(request): user = request.user avail_quizzes = Quiz.objects.get_active_quizzes() user_answerpapers = AnswerPaper.objects.filter(user=user) - courses = Course.objects.filter(active=True) + courses = Course.objects.filter(active=True, is_trial=False) context = { 'quizzes': avail_quizzes, 'user': user, @@ -225,7 +225,7 @@ def add_quiz(request, quiz_id=None): ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this page!') - + context = {} if request.method == "POST": if quiz_id is None: form = QuizForm(request.POST, user=user) @@ -237,9 +237,11 @@ def add_quiz(request, quiz_id=None): form = QuizForm(request.POST, user=user, instance=quiz) if form.is_valid(): form.save() + context["quiz_id"]=quiz_id return my_redirect("/exam/manage/") - return my_render_to_response('yaksh/add_quiz.html', - {'form': form}, + + context["form"] = form + return my_render_to_response('yaksh/add_quiz.html', context, context_instance=ci) else: if quiz_id is None: @@ -247,8 +249,10 @@ def add_quiz(request, quiz_id=None): else: quiz = Quiz.objects.get(id=quiz_id) form = QuizForm(user=user, instance=quiz) + context["quiz_id"]=quiz_id + context["form"] = form return my_render_to_response('yaksh/add_quiz.html', - {'form': form}, + context, context_instance=ci) @@ -260,12 +264,12 @@ def show_all_questionpapers(request, questionpaper_id=None): raise Http404('You are not allowed to view this page!') if questionpaper_id is None: - qu_papers = QuestionPaper.objects.all() + qu_papers = QuestionPaper.objects.filter(is_trial=False) context = {'papers': qu_papers} return my_render_to_response('yaksh/showquestionpapers.html', context, context_instance=ci) else: - qu_papers = QuestionPaper.objects.get(id=questionpaper_id) + qu_papers = QuestionPaper.objects.get(id=questionpaper_id,is_trial=False) quiz = qu_papers.quiz fixed_questions = qu_papers.fixed_questions.all() random_questions = qu_papers.random_questions.all() @@ -281,7 +285,11 @@ def prof_manage(request): rights/permissions and log in.""" user = request.user if user.is_authenticated() and is_moderator(user): - question_papers = QuestionPaper.objects.filter(quiz__course__creator=user) + question_papers = QuestionPaper.objects.filter(quiz__course__creator=user, + quiz__is_trial=False + ) + trial_course = Course.objects.delete_trial_course(user) + trial_quiz = Quiz.objects.delete_trial_quiz(user) users_per_paper = [] for paper in question_papers: answer_papers = AnswerPaper.objects.filter(question_paper=paper) @@ -580,7 +588,7 @@ def add_course(request): def enroll_request(request, course_id): user = request.user ci = RequestContext(request) - course = get_object_or_404(Course, pk=course_id) + course = get_object_or_404(Course, pk=course_id, is_trial=False) course.request(user) return my_redirect('/exam/manage/') @@ -589,7 +597,7 @@ def enroll_request(request, course_id): def self_enroll(request, course_id): user = request.user ci = RequestContext(request) - course = get_object_or_404(Course, pk=course_id) + course = get_object_or_404(Course, pk=course_id, is_trial=False) if course.is_self_enroll(): was_rejected = False course.enroll(was_rejected, user) @@ -602,7 +610,7 @@ def courses(request): ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this page') - courses = Course.objects.filter(creator=user) + courses = Course.objects.filter(creator=user, is_trial=False) return my_render_to_response('yaksh/courses.html', {'courses': courses}, context_instance=ci) @@ -615,7 +623,7 @@ def course_detail(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id) + course = get_object_or_404(Course, pk=course_id, is_trial=False) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -630,7 +638,7 @@ def enroll(request, course_id, user_id=None, was_rejected=False): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id) + course = get_object_or_404(Course, pk=course_id, is_trial=False) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -653,7 +661,7 @@ def reject(request, course_id, user_id=None, was_enrolled=False): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id) + course = get_object_or_404(Course, pk=course_id, is_trial=False) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -675,7 +683,7 @@ def toggle_course_status(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id) + course = get_object_or_404(Course, pk=course_id, is_trial=False) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -723,8 +731,10 @@ def monitor(request, questionpaper_id=None): raise Http404('You are not allowed to view this page!') if questionpaper_id is None: - q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user)| - Q(quiz__course__teachers=user)).distinct() + q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user) + | Q(quiz__course__teachers=user), + quiz__course__is_trial=False + ).distinct() context = {'papers': [], 'quiz': None, 'quizzes': q_paper} @@ -733,7 +743,7 @@ def monitor(request, questionpaper_id=None): # quiz_id is not None. try: q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user)| - Q(quiz__course__teachers=user), + Q(quiz__course__teachers=user), quiz__course__is_trial=False, id=questionpaper_id).distinct() except QuestionPaper.DoesNotExist: papers = [] @@ -834,6 +844,13 @@ def show_all_questions(request): else: msg = "Please select atleast one question" context['msg'] = msg + if request.POST.get('test') == 'test': + question_ids = request.POST.getlist("question") + trial_paper = test_mode(user, "test_questions", question_ids, None) + trial_paper.update_total_marks() + trial_paper.save() + return my_redirect("/exam/start/{0}".format(trial_paper.id)) + questions = Question.objects.filter(user_id=user.id) form = QuestionFilterForm(user=user) @@ -866,7 +883,7 @@ def download_csv(request, questionpaper_id): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') - quiz = Quiz.objects.get(questionpaper=questionpaper_id) + quiz = Quiz.objects.get(questionpaper=questionpaper_id,is_trial=False) if not quiz.course.is_creator(user) and not quiz.course.is_teacher(user): raise Http404('The question paper does not belong to your course') @@ -917,7 +934,7 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): if not current_user.is_authenticated() or not is_moderator(current_user): raise Http404('You are not allowed to view this page!') course_details = Course.objects.filter(Q(creator=current_user)| - Q(teachers=current_user)).distinct() + Q(teachers=current_user), is_trial=False).distinct() context = {"course_details": course_details} if quiz_id is not None: questionpaper_id = QuestionPaper.objects.filter(quiz_id=quiz_id)\ @@ -1099,7 +1116,7 @@ def search_teacher(request, course_id): raise Http404('You are not allowed to view this page!') context = {} - course = get_object_or_404(Course, creator=user, pk=course_id) + course = get_object_or_404(Course, creator=user, pk=course_id, is_trial=False) context['course'] = course if request.method == 'POST': @@ -1131,7 +1148,7 @@ def add_teacher(request, course_id): raise Http404('You are not allowed to view this page!') context = {} - course = get_object_or_404(Course, creator=user, pk=course_id) + course = get_object_or_404(Course, creator=user, pk=course_id, is_trial=False) context['course'] = course if request.method == 'POST': @@ -1157,7 +1174,7 @@ def allotted_courses(request): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - courses = Course.objects.filter(teachers=user) + courses = Course.objects.filter(teachers=user, is_trial=False) return my_render_to_response('yaksh/courses.html', {'courses': courses}, context_instance=ci) @@ -1170,9 +1187,29 @@ def remove_teachers(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - course = get_object_or_404(Course, creator=user, pk=course_id) + course = get_object_or_404(Course, creator=user, pk=course_id, is_trial=False) if request.method == "POST": teacher_ids = request.POST.getlist('remove') teachers = User.objects.filter(id__in=teacher_ids) course.remove_teachers(*teachers) return my_redirect('/exam/manage/courses') + +def test_mode(user, mode, questions_list=None, quiz_id=None): + if questions_list is not None and mode == "test_questions": + trial_course = Course.objects.create_trial_course(user) + trial_quiz = Quiz.objects.create_trial_quiz(trial_course,user) + trial_questionpaper = QuestionPaper.objects.add_details_trial_questionpaper(trial_quiz, + None, questions_list + ) + else: + trial_quiz = Quiz.objects.copy_original_quiz(quiz_id, user, mode) + trial_questionpaper = QuestionPaper.objects.add_details_trial_questionpaper(trial_quiz, + quiz_id, None + ) + return trial_questionpaper + +@login_required +def test_quiz(request, mode,quiz_id): + current_user = request.user + trial_questionpaper = test_mode(current_user, mode, None, quiz_id) + return my_redirect("/exam/start/{0}".format(trial_questionpaper.id)) \ No newline at end of file -- cgit From 6047d34e2f555993b2736da330302395befca8c2 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 10 May 2016 17:48:07 +0530 Subject: added model manager methods for creating trial_course,quiz and questionpaper --- yaksh/models.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 4 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 6ee02e1..9a3b606 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -4,6 +4,7 @@ from random import sample, shuffle from itertools import islice, cycle from collections import Counter from django.db import models +from django.db.models import Q from django.contrib.auth.models import User from django.forms.models import model_to_dict from django.contrib.contenttypes.models import ContentType @@ -58,6 +59,23 @@ def get_model_class(model): return model_class +############################################################################### +class CourseManager(models.Manager): + + def create_trial_course(self,user): + trial_course = self.create(name="trial_course", + enrollment="open", + creator=user, + is_trial=True + ) + was_rejected=False + trial_course.enroll(was_rejected,user) + return trial_course + + def delete_trial_course(self, user): + trial_course = self.filter(creator=user,is_trial=True) + trial_course.delete() + ############################################################################### class Course(models.Model): """ Course for students""" @@ -70,7 +88,8 @@ class Course(models.Model): rejected = models.ManyToManyField(User, related_name='rejected') created_on = models.DateTimeField(auto_now_add=True) teachers = models.ManyToManyField(User, related_name='teachers') - + is_trial = models.BooleanField(default=False) + objects = CourseManager() def request(self, *users): self.requests.add(*users) @@ -111,7 +130,7 @@ class Course(models.Model): return True if self.enrollment == enrollment_methods[1][0] else False def get_quizzes(self): - return self.quiz_set.all() + return self.quiz_set.filter(is_trial=False) def activate(self): self.active = True @@ -283,7 +302,40 @@ class Answer(models.Model): ############################################################################### class QuizManager(models.Manager): def get_active_quizzes(self): - return self.filter(active=True) + return self.filter(active=True,is_trial=False) + + def create_trial_quiz(self,trial_course,user): + trial_quiz = self.create(course=trial_course, + duration=1000, + description="trial_quiz", + is_trial=True, + time_between_attempts=0 + ) + return trial_quiz + + def copy_original_quiz(self, original_quiz_id, user, mode): + was_rejected = False + trial_quiz = self.get(id=original_quiz_id) + trial_quiz.course.enroll(was_rejected,user) + trial_quiz.pk = None + trial_quiz.description += "trial_" + trial_quiz.is_trial = True + if mode == "godmode": + trial_quiz.duration = 1000 + trial_quiz.active = True + trial_quiz.start_date_time = datetime.now() + trial_quiz.end_date_time = datetime(2199, 1, 1, 0, 0, 0, 0) + trial_quiz.time_between_attempts = 0 + trial_quiz.save() + return trial_quiz + + def delete_trial_quiz(self, user): + trial_quiz = self.filter(Q(course__creator=user)|Q(course__teachers=user), + is_trial=True + ) + trial_quiz.delete() + + ############################################################################### class Quiz(models.Model): """A quiz that students will participate in. One can think of this @@ -329,6 +381,8 @@ class Quiz(models.Model): time_between_attempts = models.IntegerField("Number of Days",\ choices=days_between_attempts) + is_trial = models.BooleanField(default=False) + objects = QuizManager() class Meta: @@ -340,13 +394,52 @@ class Quiz(models.Model): def has_prerequisite(self): return True if self.prerequisite else False - + def __unicode__(self): desc = self.description or 'Quiz' return '%s: on %s for %d minutes' % (desc, self.start_date_time, self.duration) +############################################################################### +class QuestionPaperManager(models.Manager): + + def _copy_original_questionpaper(self, original_quiz_id): + trial_questionpaper = self.get(quiz_id = original_quiz_id) + trial_questions = {"fixed_questions": trial_questionpaper\ + .fixed_questions.all(), + "random_questions": trial_questionpaper\ + .random_questions.all() + } + trial_questionpaper.pk = None + trial_questionpaper.save() + return trial_questionpaper, trial_questions + + def _create_trial_questionpaper(self, trial_quiz): + trial_questionpaper=self.create(quiz=trial_quiz, + total_marks=10, + ) + return trial_questionpaper + + def add_details_trial_questionpaper(self, trial_quiz, + original_quiz_id=None, + questions_list=None): + if questions_list is not None and original_quiz_id is None: + trial_questionpaper = self._create_trial_questionpaper(trial_quiz) + trial_questionpaper.fixed_questions.add(*questions_list) + + else: + trial_questionpaper, trial_questions = self._copy_original_questionpaper\ + (original_quiz_id) + trial_questionpaper.quiz = trial_quiz + trial_questionpaper.fixed_questions\ + .add(*trial_questions["fixed_questions"]) + trial_questionpaper.random_questions\ + .add(*trial_questions["random_questions"]) + trial_questionpaper.save() + return trial_questionpaper + + ############################################################################### class QuestionPaper(models.Model): """Question paper stores the detail of the questions.""" @@ -366,6 +459,10 @@ class QuestionPaper(models.Model): # Total marks for the question paper. total_marks = models.FloatField() +# is_trial = models.BooleanField(default=False) + + objects = QuestionPaperManager() + def update_total_marks(self): """ Updates the total marks for the Question Paper""" marks = 0.0 -- cgit From fd146db8ed52d62552c4e27de0b2d803a7e5b4b8 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 10 May 2016 17:49:44 +0530 Subject: excludes is_trial in course, quiz forms --- yaksh/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index 26e0967..b61dc31 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -163,7 +163,7 @@ class QuizForm(forms.ModelForm): class Meta: model = Quiz - fields = '__all__' + exclude = ["is_trial"] class QuestionForm(forms.ModelForm): @@ -204,7 +204,7 @@ class CourseForm(forms.ModelForm): class Meta: model = Course fields = ['name', 'active', 'enrollment'] - + exclude = ["is_trial"] class ProfileForm(forms.ModelForm): """ profile form for students and moderators """ -- cgit From 04a4189f5c5786ff121a68f8f191505bbbde0603 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 10 May 2016 17:50:22 +0530 Subject: added urls for test_modes --- yaksh/urls.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/urls.py b/yaksh/urls.py index feac8c1..d7b56e4 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -90,7 +90,8 @@ urlpatterns += [ url(r'^manage/allotted_course/$', views.allotted_courses), url(r'^manage/remove_teachers/(?P\d+)/$', views.remove_teachers), url(r'^manage/download_questions/$', views.show_all_questions), - url(r'^manage/upload_questions/$', views.show_all_questions) + url(r'^manage/upload_questions/$', views.show_all_questions), + url(r'^manage/(?P[\w\-]+)/(?P\d+)/$', views.test_quiz) ] -- cgit From df0595e1f3d3dbb2b1a11967fdac053e089a714e Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 10 May 2016 17:51:42 +0530 Subject: added test mode buttons in addquiz --- yaksh/templates/yaksh/add_quiz.html | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/add_quiz.html b/yaksh/templates/yaksh/add_quiz.html index c47d1f7..8c3df63 100644 --- a/yaksh/templates/yaksh/add_quiz.html +++ b/yaksh/templates/yaksh/add_quiz.html @@ -22,4 +22,9 @@
+{% if quiz_id %} +

You can check the quiz by attempting it in the following modes:

+ + + {% endif %} {% endblock %} -- cgit From 271e3e3eed59642ea6f2365758ca7609ab307f65 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 10 May 2016 17:52:34 +0530 Subject: added test selected button in showquestions --- yaksh/templates/yaksh/showquestions.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html index ea42797..2f4d218 100644 --- a/yaksh/templates/yaksh/showquestions.html +++ b/yaksh/templates/yaksh/showquestions.html @@ -57,7 +57,8 @@       {% if questions %} - +   + {% endif %} {% endblock %} -- cgit From 85e19a0c1c8dca0a187d151a21927d89a81a7341 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 11 May 2016 15:23:28 +0530 Subject: minor changes in redirection for test_mode --- yaksh/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 019b631..5651a80 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -849,7 +849,7 @@ def show_all_questions(request): trial_paper = test_mode(user, "test_questions", question_ids, None) trial_paper.update_total_marks() trial_paper.save() - return my_redirect("/exam/start/{0}".format(trial_paper.id)) + return my_redirect("/exam/start/1/{0}".format(trial_paper.id)) questions = Question.objects.filter(user_id=user.id) @@ -1212,4 +1212,4 @@ def test_mode(user, mode, questions_list=None, quiz_id=None): def test_quiz(request, mode,quiz_id): current_user = request.user trial_questionpaper = test_mode(current_user, mode, None, quiz_id) - return my_redirect("/exam/start/{0}".format(trial_questionpaper.id)) \ No newline at end of file + return my_redirect("/exam/start/1/{0}".format(trial_questionpaper.id)) \ No newline at end of file -- cgit From c4ca9893f831d05bf5e38323533eee249be2baf4 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:16:34 +0530 Subject: added tests to usermode, godmode and test questions --- yaksh/tests.py | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 3 deletions(-) (limited to 'yaksh') diff --git a/yaksh/tests.py b/yaksh/tests.py index f2083dd..120db60 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -6,6 +6,7 @@ import json from datetime import datetime, timedelta from django.contrib.auth.models import Group + def setUpModule(): # create user profile user = User.objects.create_user(username='demo_user', @@ -153,9 +154,12 @@ class QuestionTestCases(unittest.TestCase): ############################################################################### class QuizTestCases(unittest.TestCase): def setUp(self): + self.creator = User.objects.get(pk=1) + self.teacher = User.objects.get(pk=2) self.quiz1 = Quiz.objects.get(pk=1) self.quiz2 = Quiz.objects.get(pk=2) - + self.trial_course = Course.objects.create_trial_course(self.creator) + def test_quiz(self): """ Test Quiz""" self.assertEqual((self.quiz1.start_date_time).strftime('%Y-%m-%d'), @@ -182,6 +186,69 @@ class QuizTestCases(unittest.TestCase): for quiz in quizzes: self.assertTrue(quiz.active) + def test_create_trial_quiz(self): + """Test to check if trial quiz is created""" + trial_quiz = Quiz.objects.create_trial_quiz(self.trial_course, + self.creator + ) + self.assertEqual(trial_quiz.course, self.trial_course) + self.assertEqual(trial_quiz.duration, 1000) + self.assertEqual(trial_quiz.description, "trial_quiz") + self.assertTrue(trial_quiz.is_trial) + self.assertEqual(trial_quiz.time_between_attempts, 0) + + def test_create_trial_from_quiz_godmode(self): + """Test to check if a copy of original quiz is created in godmode""" + trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id, + self.creator, + "godmode" + ) + self.assertEqual(trial_quiz.description, "demo quiz_trial") + self.assertTrue(trial_quiz.is_trial) + self.assertEqual(trial_quiz.duration, 1000) + self.assertTrue(trial_quiz.active) + self.assertEqual(trial_quiz.end_date_time, + datetime(2199, 1, 1, 0, 0, 0, 0) + ) + self.assertEqual(trial_quiz.time_between_attempts, 0) + + def test_create_trial_from_quiz_usermode(self): + """Test to check if a copy of original quiz is created in usermode""" + trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id, + self.creator, + "usermode" + ) + self.assertEqual(trial_quiz.description, "demo quiz_trial") + self.assertTrue(trial_quiz.is_trial) + self.assertEqual(trial_quiz.duration, self.quiz1.duration) + self.assertEqual(trial_quiz.active, self.quiz1.active) + self.assertEqual(trial_quiz.start_date_time, + self.quiz1.start_date_time + ) + self.assertEqual(trial_quiz.end_date_time, + self.quiz1.end_date_time + ) + self.assertEqual(trial_quiz.time_between_attempts, 0) + + def test_delete_all_trial_quizzes_creator(self): + Quiz.objects.create_trial_from_quiz(self.quiz1.id, + self.creator, + "godmode" + ) + Quiz.objects.delete_all_trial_quizzes(self.creator) + self.assertFalse(Quiz.objects.filter(course__creator=self.creator, + is_trial=True).exists() + ) + def test_delete_all_trial_quizzes_added_teacher(self): + self.trial_course.add_teachers(self.teacher) + Quiz.objects.create_trial_from_quiz(self.quiz1.id, + self.creator, + "godmode" + ) + Quiz.objects.delete_all_trial_quizzes(self.teacher) + self.assertFalse(Quiz.objects.filter(course__teachers=self.teacher, + is_trial=True).exists() + ) ############################################################################### class QuestionPaperTestCases(unittest.TestCase): @@ -239,6 +306,11 @@ class QuestionPaperTestCases(unittest.TestCase): user=self.user ) + ### For Test case + self.questions_list=[self.questions[3].id, self.questions[5].id] + trial_course = Course.objects.create_trial_course(self.user) + trial_quiz = Quiz.objects.create_trial_quiz(trial_course, self.user) + def test_questionpaper(self): """ Test question paper""" self.assertEqual(self.question_paper.quiz.description, 'demo quiz') @@ -291,7 +363,28 @@ class QuestionPaperTestCases(unittest.TestCase): # test can_attempt_now(self): self.assertFalse(self.question_paper.can_attempt_now(self.user)) - + def test_create_trial_paper_test_quiz(self): + trial_paper = QuestionPaper.objects.create_trial_paper_test_questions\ + (trial_quiz, + self.question_paper.id + ) + self.assertEqual(trial_paper.quiz, trial_quiz) + self.assertEqual(trial_paper.fixed_questions.all(), + self.question_paper.fixed_questions.all() + ) + self.assertEqual(trial_paper.random_questions.all(), + self.question_paper.random_questions.all() + ) + + def test_create_trial_paper_test_questions(self): + trial_paper = QuestionPaper.objects.create_trial_paper(trial_quiz, + self.questions_list + ) + self.assertEqual(trial_paper.quiz, trial_quiz) + self.assertEqual(self.questions_list, + self.question_paper.fixed_questions\ + .values_list("id", flat=True) + ) ############################################################################### class AnswerPaperTestCases(unittest.TestCase): @classmethod @@ -427,6 +520,7 @@ class CourseTestCases(unittest.TestCase): self.quiz1 = Quiz.objects.get(pk=1) self.quiz2 = Quiz.objects.get(pk=2) + def test_is_creator(self): """ Test is_creator method of Course""" self.assertTrue(self.course.is_creator(self.creator)) @@ -499,6 +593,21 @@ class CourseTestCases(unittest.TestCase): result = self.course.is_teacher(self.student2) self.assertTrue(result) + def test_create_trial_course(self): + """Test to check if trial course is created""" + # Test for manager method create_trial_course + trial_course = Course.objects.create_trial_course(self.creator) + self.assertEqual(trial_course.name,"trial_course") + self.assertEqual(trial_course.enrollment, "open") + self.assertTrue(trial_course.active) + self.assertEqual(trial_course.students.get(user=self.creator.id), self.creator) + self.assertTrue(trial_course.is_trial) + + def test_delete_all_trial_courses(self): + Course.objects.create_trial_course(self.creator) + Course.objects.delete_all_trial_courses(self.creator) + self.assertFalse(Course.objects.filter(creator=self.creator, is_trial=True).exists()) + ############################################################################### class TestCaseTestCases(unittest.TestCase): @@ -561,4 +670,4 @@ class TestCaseTestCases(unittest.TestCase): result = self.question1.consolidate_answer_data( user_answer="demo_answer" ) - self.assertEqual(result, self.answer_data_json) \ No newline at end of file + self.assertEqual(result, self.answer_data_json) -- cgit From 3fce86f44fa52d5ae04591a316d5b680d105dbcc Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:17:16 +0530 Subject: changed model manager names --- yaksh/models.py | 59 +++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 9a3b606..0303321 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -63,16 +63,17 @@ def get_model_class(model): class CourseManager(models.Manager): def create_trial_course(self,user): + """Creates a trial course for testing questions""" trial_course = self.create(name="trial_course", enrollment="open", creator=user, is_trial=True ) - was_rejected=False - trial_course.enroll(was_rejected,user) + trial_course.enroll(False,user) return trial_course - def delete_trial_course(self, user): + def delete_all_trial_courses(self, user): + """Deletes all trial course for a user.""" trial_course = self.filter(creator=user,is_trial=True) trial_course.delete() @@ -305,6 +306,7 @@ class QuizManager(models.Manager): return self.filter(active=True,is_trial=False) def create_trial_quiz(self,trial_course,user): + """Creates a trial quiz for testing questions""" trial_quiz = self.create(course=trial_course, duration=1000, description="trial_quiz", @@ -313,23 +315,24 @@ class QuizManager(models.Manager): ) return trial_quiz - def copy_original_quiz(self, original_quiz_id, user, mode): - was_rejected = False + def create_trial_from_quiz(self, original_quiz_id, user, mode): + """Creates a trial quiz from existing quiz""" trial_quiz = self.get(id=original_quiz_id) - trial_quiz.course.enroll(was_rejected,user) + trial_quiz.course.enroll(False, user) trial_quiz.pk = None - trial_quiz.description += "trial_" + trial_quiz.description += "_trial" trial_quiz.is_trial = True + trial_quiz.time_between_attempts = 0 + trial_quiz.prerequisite = None if mode == "godmode": trial_quiz.duration = 1000 trial_quiz.active = True trial_quiz.start_date_time = datetime.now() trial_quiz.end_date_time = datetime(2199, 1, 1, 0, 0, 0, 0) - trial_quiz.time_between_attempts = 0 trial_quiz.save() - return trial_quiz + return trial_quiz - def delete_trial_quiz(self, user): + def delete_all_trial_quizzes(self, user): trial_quiz = self.filter(Q(course__creator=user)|Q(course__teachers=user), is_trial=True ) @@ -404,7 +407,7 @@ class Quiz(models.Model): ############################################################################### class QuestionPaperManager(models.Manager): - def _copy_original_questionpaper(self, original_quiz_id): + def _create_trial_from_questionpaper(self, original_quiz_id): trial_questionpaper = self.get(quiz_id = original_quiz_id) trial_questions = {"fixed_questions": trial_questionpaper\ .fixed_questions.all(), @@ -414,32 +417,26 @@ class QuestionPaperManager(models.Manager): trial_questionpaper.pk = None trial_questionpaper.save() return trial_questionpaper, trial_questions - - def _create_trial_questionpaper(self, trial_quiz): - trial_questionpaper=self.create(quiz=trial_quiz, + + def create_trial_paper_to_test_questions(self, trial_quiz, questions_list): + if questions_list is not None: + trial_questionpaper=self.create(quiz=trial_quiz, total_marks=10, ) - return trial_questionpaper - - def add_details_trial_questionpaper(self, trial_quiz, - original_quiz_id=None, - questions_list=None): - if questions_list is not None and original_quiz_id is None: - trial_questionpaper = self._create_trial_questionpaper(trial_quiz) trial_questionpaper.fixed_questions.add(*questions_list) - - else: - trial_questionpaper, trial_questions = self._copy_original_questionpaper\ - (original_quiz_id) - trial_questionpaper.quiz = trial_quiz - trial_questionpaper.fixed_questions\ - .add(*trial_questions["fixed_questions"]) - trial_questionpaper.random_questions\ - .add(*trial_questions["random_questions"]) + return trial_questionpaper + + def create_trial_paper_to_test_quiz(self, trial_quiz, original_quiz_id): + trial_questionpaper, trial_questions = self._create_trial_from_questionpaper\ + (original_quiz_id) + trial_questionpaper.quiz = trial_quiz + trial_questionpaper.fixed_questions\ + .add(*trial_questions["fixed_questions"]) + trial_questionpaper.random_questions\ + .add(*trial_questions["random_questions"]) trial_questionpaper.save() return trial_questionpaper - ############################################################################### class QuestionPaper(models.Model): """Question paper stores the detail of the questions.""" -- cgit From 986e3e71b3ec858f2a7e603679c44a80fe3d4558 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:18:33 +0530 Subject: minor changes in test_mode function --- yaksh/views.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 5651a80..53c9372 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -130,7 +130,6 @@ def quizlist_user(request): 'courses': courses, 'quizzes_taken': user_answerpapers, } - return my_render_to_response("yaksh/quizzes_user.html", context) @@ -288,8 +287,8 @@ rights/permissions and log in.""" question_papers = QuestionPaper.objects.filter(quiz__course__creator=user, quiz__is_trial=False ) - trial_course = Course.objects.delete_trial_course(user) - trial_quiz = Quiz.objects.delete_trial_quiz(user) + trial_course = Course.objects.delete_all_trial_courses(user) + trial_quiz = Quiz.objects.delete_all_trial_quizzes(user) users_per_paper = [] for paper in question_papers: answer_papers = AnswerPaper.objects.filter(question_paper=paper) @@ -350,8 +349,12 @@ def start(request, questionpaper_id=None, attempt_num=None): if not quest_paper.quiz.course.is_enrolled(user) : raise Http404('You are not allowed to view this page!') # prerequisite check and passing criteria + if quest_paper.quiz.is_expired(): + if is_moderator(user): + return redirect("/exam/manage") + return redirect("/exam/quizzes") if quest_paper.quiz.has_prerequisite() and not quest_paper.is_prerequisite_passed(user): - return quizlist_user(request) + return redirect("/exam/quizzes") # if any previous attempt last_attempt = AnswerPaper.objects.get_user_last_attempt( questionpaper=quest_paper, user=user) @@ -359,7 +362,7 @@ def start(request, questionpaper_id=None, attempt_num=None): return show_question(request, last_attempt.current_question(), last_attempt) # allowed to start if not quest_paper.can_attempt_now(user): - return quizlist_user(request) + return redirect("/exam/quizzes") if attempt_num is None: attempt_number = 1 if not last_attempt else last_attempt.attempt_number +1 context = {'user': user, 'questionpaper': quest_paper, @@ -806,7 +809,7 @@ def ajax_questions_filter(request): @login_required def show_all_questions(request): - """Show a list of all the questions currently in the databse.""" + """Show a list of all the questions currently in the database.""" user = request.user ci = RequestContext(request) @@ -844,6 +847,7 @@ def show_all_questions(request): else: msg = "Please select atleast one question" context['msg'] = msg + if request.POST.get('test') == 'test': question_ids = request.POST.getlist("question") trial_paper = test_mode(user, "test_questions", question_ids, None) @@ -1194,22 +1198,26 @@ def remove_teachers(request, course_id): course.remove_teachers(*teachers) return my_redirect('/exam/manage/courses') -def test_mode(user, mode, questions_list=None, quiz_id=None): +def test_mode(user, mode, questions_list=None, quiz_id=None): + """creates a trial question paper for the moderators""" + if questions_list is not None and mode == "test_questions": trial_course = Course.objects.create_trial_course(user) trial_quiz = Quiz.objects.create_trial_quiz(trial_course,user) - trial_questionpaper = QuestionPaper.objects.add_details_trial_questionpaper(trial_quiz, - None, questions_list - ) + trial_questionpaper = QuestionPaper.objects\ + .create_trial_paper_to_test_questions\ + (trial_quiz, questions_list) else: - trial_quiz = Quiz.objects.copy_original_quiz(quiz_id, user, mode) - trial_questionpaper = QuestionPaper.objects.add_details_trial_questionpaper(trial_quiz, - quiz_id, None - ) + trial_quiz = Quiz.objects.create_trial_from_quiz(quiz_id, user, mode) + trial_questionpaper = QuestionPaper.objects\ + .create_trial_paper_to_test_quiz\ + (trial_quiz, quiz_id) return trial_questionpaper @login_required def test_quiz(request, mode,quiz_id): + """creates a trial quiz for the moderators""" + current_user = request.user trial_questionpaper = test_mode(current_user, mode, None, quiz_id) - return my_redirect("/exam/start/1/{0}".format(trial_questionpaper.id)) \ No newline at end of file + return my_redirect("/exam/start/{0}".format(trial_questionpaper.id)) \ No newline at end of file -- cgit From c69c414120f85ed61b62451bae3b806d93c52361 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:19:34 +0530 Subject: added js function to alert user for prerequisites --- yaksh/static/yaksh/js/add_quiz.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'yaksh') diff --git a/yaksh/static/yaksh/js/add_quiz.js b/yaksh/static/yaksh/js/add_quiz.js index 184881c..e212b70 100644 --- a/yaksh/static/yaksh/js/add_quiz.js +++ b/yaksh/static/yaksh/js/add_quiz.js @@ -9,3 +9,12 @@ function test() document.getElementById("submit").innerHTML = "Save"; } } + +function usermode(location) +{ + var select = document.getElementById("id_prerequisite"); + var select_text = select.options[select.selectedIndex].text; + window.alert(select_text + " is a prerequisite for this course.\n \ + You are still allowed to attempt this quiz.") + window.location.replace(location); +} \ No newline at end of file -- cgit From 65d8a3d090af8c126fe3dc755050be13dd99283a Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:20:54 +0530 Subject: added help for user mode and god mode --- yaksh/templates/yaksh/add_quiz.html | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/add_quiz.html b/yaksh/templates/yaksh/add_quiz.html index 8c3df63..5a0bee4 100644 --- a/yaksh/templates/yaksh/add_quiz.html +++ b/yaksh/templates/yaksh/add_quiz.html @@ -11,6 +11,7 @@ {% endblock %} {% block onload %} onload="javascript:test();" {% endblock %} {% block manage %} +
{% csrf_token %}
@@ -18,13 +19,33 @@ {{ form.as_table }}
- +
+
+
{% if quiz_id %} -

You can check the quiz by attempting it in the following modes:

- - + +
You can check the quiz by attempting it in the following modes:
+
+ + + + Help +
+
+ {% endif %} {% endblock %} -- cgit From 03b6bda58ec1af0ceb0de9f26d25bc342e550310 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:37:24 +0530 Subject: added docstrings to manager methods --- yaksh/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 0303321..1875fd2 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -408,6 +408,7 @@ class Quiz(models.Model): class QuestionPaperManager(models.Manager): def _create_trial_from_questionpaper(self, original_quiz_id): + """Creates a copy of the original questionpaper""" trial_questionpaper = self.get(quiz_id = original_quiz_id) trial_questions = {"fixed_questions": trial_questionpaper\ .fixed_questions.all(), @@ -418,7 +419,9 @@ class QuestionPaperManager(models.Manager): trial_questionpaper.save() return trial_questionpaper, trial_questions - def create_trial_paper_to_test_questions(self, trial_quiz, questions_list): + def create_trial_paper_to_test_questions(self, trial_quiz, + questions_list): + """Creates a trial question paper to test selected questions""" if questions_list is not None: trial_questionpaper=self.create(quiz=trial_quiz, total_marks=10, @@ -427,6 +430,7 @@ class QuestionPaperManager(models.Manager): return trial_questionpaper def create_trial_paper_to_test_quiz(self, trial_quiz, original_quiz_id): + """Creates a trial question paper to test quiz.""" trial_questionpaper, trial_questions = self._create_trial_from_questionpaper\ (original_quiz_id) trial_questionpaper.quiz = trial_quiz -- cgit From 669c84765fd79e5431ebe4fb20aa122133e0c5c1 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:46:31 +0530 Subject: fixed model manager method name changes in testcases --- yaksh/tests.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'yaksh') diff --git a/yaksh/tests.py b/yaksh/tests.py index 120db60..5dc551f 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -363,8 +363,8 @@ class QuestionPaperTestCases(unittest.TestCase): # test can_attempt_now(self): self.assertFalse(self.question_paper.can_attempt_now(self.user)) - def test_create_trial_paper_test_quiz(self): - trial_paper = QuestionPaper.objects.create_trial_paper_test_questions\ + def test_create_trial_paper_to_test_quiz(self): + trial_paper = QuestionPaper.objects.create_trial_paper_to_test_quiz\ (trial_quiz, self.question_paper.id ) @@ -376,10 +376,11 @@ class QuestionPaperTestCases(unittest.TestCase): self.question_paper.random_questions.all() ) - def test_create_trial_paper_test_questions(self): - trial_paper = QuestionPaper.objects.create_trial_paper(trial_quiz, - self.questions_list - ) + def test_create_trial_paper_to_test_questions(self): + trial_paper = QuestionPaper.objects.\ + create_trial_paper_to_test_questions( + trial_quiz, self.questions_list + ) self.assertEqual(trial_paper.quiz, trial_quiz) self.assertEqual(self.questions_list, self.question_paper.fixed_questions\ @@ -602,7 +603,7 @@ class CourseTestCases(unittest.TestCase): self.assertTrue(trial_course.active) self.assertEqual(trial_course.students.get(user=self.creator.id), self.creator) self.assertTrue(trial_course.is_trial) - + def test_delete_all_trial_courses(self): Course.objects.create_trial_course(self.creator) Course.objects.delete_all_trial_courses(self.creator) -- cgit From 14b1408c291c644ec5748e029ac1ae39e9ac3913 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 13 May 2016 18:46:46 +0530 Subject: fixed model manager method name changes in testcases --- yaksh/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 1875fd2..3a2506c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -421,7 +421,7 @@ class QuestionPaperManager(models.Manager): def create_trial_paper_to_test_questions(self, trial_quiz, questions_list): - """Creates a trial question paper to test selected questions""" + """Creates a trial question paper to test selected questions""" if questions_list is not None: trial_questionpaper=self.create(quiz=trial_quiz, total_marks=10, -- cgit From 175153cc5daeccd80bfa0184114ebf01bae93013 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Mon, 16 May 2016 12:42:35 +0530 Subject: added no prerequisite required condition --- yaksh/static/yaksh/js/add_quiz.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'yaksh') diff --git a/yaksh/static/yaksh/js/add_quiz.js b/yaksh/static/yaksh/js/add_quiz.js index e212b70..33358a7 100644 --- a/yaksh/static/yaksh/js/add_quiz.js +++ b/yaksh/static/yaksh/js/add_quiz.js @@ -10,11 +10,21 @@ function test() } } +String.prototype.beginsWith = function (string) { + return(this.indexOf(string) === 0); +}; + function usermode(location) { var select = document.getElementById("id_prerequisite"); var select_text = select.options[select.selectedIndex].text; - window.alert(select_text + " is a prerequisite for this course.\n \ - You are still allowed to attempt this quiz.") - window.location.replace(location); -} \ No newline at end of file + if (select_text.beginsWith("----")){ + window.alert("No prerequisite for this course.\n \ + You can attempt the quiz."); + window.location.replace(location); + } else { + window.alert(select_text + " is a prerequisite for this course.\n \ + You are still allowed to attempt this quiz.") + window.location.replace(location); + } + } \ No newline at end of file -- cgit From 4f94c550a16654c6723a8c09cff6557a135f4747 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Mon, 16 May 2016 12:43:39 +0530 Subject: home button will redirect moderators to exam/manage instead of exam/quizzes --- yaksh/templates/yaksh/intro.html | 5 ++++- yaksh/views.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/intro.html b/yaksh/templates/yaksh/intro.html index f05e9a1..b4bc6d7 100644 --- a/yaksh/templates/yaksh/intro.html +++ b/yaksh/templates/yaksh/intro.html @@ -39,8 +39,11 @@

We hope you enjoy taking this exam !!!

- + {% if user == "moderator" %} +
+ {%else%} + {% endif %} {% csrf_token %}
diff --git a/yaksh/views.py b/yaksh/views.py index 53c9372..989abf7 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -367,6 +367,8 @@ def start(request, questionpaper_id=None, attempt_num=None): attempt_number = 1 if not last_attempt else last_attempt.attempt_number +1 context = {'user': user, 'questionpaper': quest_paper, 'attempt_num': attempt_number} + if is_moderator(user): + context["user"] = "moderator" return my_render_to_response('yaksh/intro.html', context, context_instance=ci) else: -- cgit From 1be1ec716c4a154be009ccaea404c16505e47bf1 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Sat, 21 May 2016 12:03:11 +0530 Subject: removed exclude from course form --- yaksh/forms.py | 1 - 1 file changed, 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index b61dc31..8b864d0 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -204,7 +204,6 @@ class CourseForm(forms.ModelForm): class Meta: model = Course fields = ['name', 'active', 'enrollment'] - exclude = ["is_trial"] class ProfileForm(forms.ModelForm): """ profile form for students and moderators """ -- cgit From bfea715def3401af2f984d133e2d6dfdc72964ba Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 27 May 2016 13:19:19 +0530 Subject: removed HttpRequest from imports in views --- yaksh/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 989abf7..23024b2 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -6,7 +6,7 @@ from os.path import dirname, pardir, abspath, join, exists from datetime import datetime import collections import csv -from django.http import HttpResponse, HttpRequest +from django.http import HttpResponse 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 -- cgit From b7b4a4c4cbcd29c3f5f02216705b04c635439b8a Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Fri, 27 May 2016 17:00:34 +0530 Subject: modified to make code pep8 compliant --- yaksh/models.py | 56 +++++++++++++++++++++++------------------------ yaksh/tests.py | 56 ++++++++++++++++++++++++++--------------------- yaksh/views.py | 67 +++++++++++++++++++++++++++++++-------------------------- 3 files changed, 97 insertions(+), 82 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 3a2506c..ec9a84b 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -7,7 +7,7 @@ from django.db import models from django.db.models import Q from django.contrib.auth.models import User from django.forms.models import model_to_dict -from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.models import ContentType from taggit.managers import TaggableManager from django.utils import timezone import pytz @@ -62,21 +62,19 @@ def get_model_class(model): ############################################################################### class CourseManager(models.Manager): - def create_trial_course(self,user): + def create_trial_course(self, user): """Creates a trial course for testing questions""" - trial_course = self.create(name="trial_course", - enrollment="open", - creator=user, - is_trial=True - ) - trial_course.enroll(False,user) + trial_course = self.create(name="trial_course", enrollment="open", + creator=user, is_trial=True) + trial_course.enroll(False, user) return trial_course def delete_all_trial_courses(self, user): """Deletes all trial course for a user.""" - trial_course = self.filter(creator=user,is_trial=True) + trial_course = self.filter(creator=user, is_trial=True) trial_course.delete() + ############################################################################### class Course(models.Model): """ Course for students""" @@ -300,19 +298,20 @@ class Answer(models.Model): def __unicode__(self): return self.answer + ############################################################################### class QuizManager(models.Manager): def get_active_quizzes(self): - return self.filter(active=True,is_trial=False) + return self.filter(active=True, is_trial=False) - def create_trial_quiz(self,trial_course,user): + def create_trial_quiz(self, trial_course, user): """Creates a trial quiz for testing questions""" trial_quiz = self.create(course=trial_course, duration=1000, description="trial_quiz", is_trial=True, time_between_attempts=0 - ) + ) return trial_quiz def create_trial_from_quiz(self, original_quiz_id, user, mode): @@ -333,9 +332,9 @@ class QuizManager(models.Manager): return trial_quiz def delete_all_trial_quizzes(self, user): - trial_quiz = self.filter(Q(course__creator=user)|Q(course__teachers=user), - is_trial=True - ) + trial_quiz = self.filter(Q(course__creator=user) | + Q(course__teachers=user), is_trial=True + ) trial_quiz.delete() @@ -409,38 +408,39 @@ class QuestionPaperManager(models.Manager): def _create_trial_from_questionpaper(self, original_quiz_id): """Creates a copy of the original questionpaper""" - trial_questionpaper = self.get(quiz_id = original_quiz_id) - trial_questions = {"fixed_questions": trial_questionpaper\ - .fixed_questions.all(), - "random_questions": trial_questionpaper\ - .random_questions.all() - } + trial_questionpaper = self.get(quiz_id=original_quiz_id) + trial_questions = {"fixed_questions": trial_questionpaper + .fixed_questions.all(), + "random_questions": trial_questionpaper + .random_questions.all() + } trial_questionpaper.pk = None trial_questionpaper.save() return trial_questionpaper, trial_questions - + def create_trial_paper_to_test_questions(self, trial_quiz, questions_list): """Creates a trial question paper to test selected questions""" if questions_list is not None: - trial_questionpaper=self.create(quiz=trial_quiz, - total_marks=10, - ) + trial_questionpaper = self.create(quiz=trial_quiz, + total_marks=10, + ) trial_questionpaper.fixed_questions.add(*questions_list) return trial_questionpaper def create_trial_paper_to_test_quiz(self, trial_quiz, original_quiz_id): """Creates a trial question paper to test quiz.""" trial_questionpaper, trial_questions = self._create_trial_from_questionpaper\ - (original_quiz_id) + (original_quiz_id) trial_questionpaper.quiz = trial_quiz trial_questionpaper.fixed_questions\ - .add(*trial_questions["fixed_questions"]) + .add(*trial_questions["fixed_questions"]) trial_questionpaper.random_questions\ - .add(*trial_questions["random_questions"]) + .add(*trial_questions["random_questions"]) trial_questionpaper.save() return trial_questionpaper + ############################################################################### class QuestionPaper(models.Model): """Question paper stores the detail of the questions.""" diff --git a/yaksh/tests.py b/yaksh/tests.py index 5dc551f..71da672 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -151,6 +151,7 @@ class QuestionTestCases(unittest.TestCase): self.assertTrue(question_data.active) self.assertEqual(question_data.snippet, 'def fact()') + ############################################################################### class QuizTestCases(unittest.TestCase): def setUp(self): @@ -159,7 +160,7 @@ class QuizTestCases(unittest.TestCase): self.quiz1 = Quiz.objects.get(pk=1) self.quiz2 = Quiz.objects.get(pk=2) self.trial_course = Course.objects.create_trial_course(self.creator) - + def test_quiz(self): """ Test Quiz""" self.assertEqual((self.quiz1.start_date_time).strftime('%Y-%m-%d'), @@ -189,14 +190,14 @@ class QuizTestCases(unittest.TestCase): def test_create_trial_quiz(self): """Test to check if trial quiz is created""" trial_quiz = Quiz.objects.create_trial_quiz(self.trial_course, - self.creator - ) + self.creator + ) self.assertEqual(trial_quiz.course, self.trial_course) self.assertEqual(trial_quiz.duration, 1000) self.assertEqual(trial_quiz.description, "trial_quiz") self.assertTrue(trial_quiz.is_trial) self.assertEqual(trial_quiz.time_between_attempts, 0) - + def test_create_trial_from_quiz_godmode(self): """Test to check if a copy of original quiz is created in godmode""" trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id, @@ -232,23 +233,25 @@ class QuizTestCases(unittest.TestCase): def test_delete_all_trial_quizzes_creator(self): Quiz.objects.create_trial_from_quiz(self.quiz1.id, - self.creator, - "godmode" - ) + self.creator, + "godmode" + ) Quiz.objects.delete_all_trial_quizzes(self.creator) self.assertFalse(Quiz.objects.filter(course__creator=self.creator, - is_trial=True).exists() - ) + is_trial=True).exists() + ) + def test_delete_all_trial_quizzes_added_teacher(self): self.trial_course.add_teachers(self.teacher) Quiz.objects.create_trial_from_quiz(self.quiz1.id, - self.creator, - "godmode" - ) + self.creator, + "godmode" + ) Quiz.objects.delete_all_trial_quizzes(self.teacher) self.assertFalse(Quiz.objects.filter(course__teachers=self.teacher, is_trial=True).exists() - ) + ) + ############################################################################### class QuestionPaperTestCases(unittest.TestCase): @@ -306,8 +309,8 @@ class QuestionPaperTestCases(unittest.TestCase): user=self.user ) - ### For Test case - self.questions_list=[self.questions[3].id, self.questions[5].id] + # For Trial case + self.questions_list = [self.questions[3].id, self.questions[5].id] trial_course = Course.objects.create_trial_course(self.user) trial_quiz = Quiz.objects.create_trial_quiz(trial_course, self.user) @@ -365,15 +368,15 @@ class QuestionPaperTestCases(unittest.TestCase): def test_create_trial_paper_to_test_quiz(self): trial_paper = QuestionPaper.objects.create_trial_paper_to_test_quiz\ - (trial_quiz, - self.question_paper.id + (trial_quiz, + self.question_paper.id ) self.assertEqual(trial_paper.quiz, trial_quiz) self.assertEqual(trial_paper.fixed_questions.all(), - self.question_paper.fixed_questions.all() + self.question_paper.fixed_questions.all() ) self.assertEqual(trial_paper.random_questions.all(), - self.question_paper.random_questions.all() + self.question_paper.random_questions.all() ) def test_create_trial_paper_to_test_questions(self): @@ -383,9 +386,11 @@ class QuestionPaperTestCases(unittest.TestCase): ) self.assertEqual(trial_paper.quiz, trial_quiz) self.assertEqual(self.questions_list, - self.question_paper.fixed_questions\ - .values_list("id", flat=True) + self.question_paper.fixed_questions + .values_list("id", flat=True) ) + + ############################################################################### class AnswerPaperTestCases(unittest.TestCase): @classmethod @@ -598,16 +603,19 @@ class CourseTestCases(unittest.TestCase): """Test to check if trial course is created""" # Test for manager method create_trial_course trial_course = Course.objects.create_trial_course(self.creator) - self.assertEqual(trial_course.name,"trial_course") + self.assertEqual(trial_course.name, "trial_course") self.assertEqual(trial_course.enrollment, "open") self.assertTrue(trial_course.active) - self.assertEqual(trial_course.students.get(user=self.creator.id), self.creator) + self.assertEqual(trial_course.students.get(user=self.creator.id), + self.creator + ) self.assertTrue(trial_course.is_trial) def test_delete_all_trial_courses(self): Course.objects.create_trial_course(self.creator) Course.objects.delete_all_trial_courses(self.creator) - self.assertFalse(Course.objects.filter(creator=self.creator, is_trial=True).exists()) + self.assertFalse(Course.objects.filter(creator=self.creator, + is_trial=True).exists()) ############################################################################### diff --git a/yaksh/views.py b/yaksh/views.py index 23024b2..56e66e0 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -236,19 +236,19 @@ def add_quiz(request, quiz_id=None): form = QuizForm(request.POST, user=user, instance=quiz) if form.is_valid(): form.save() - context["quiz_id"]=quiz_id + 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) + context_instance=ci) else: if quiz_id is None: form = QuizForm(user=user) else: quiz = Quiz.objects.get(id=quiz_id) form = QuizForm(user=user, instance=quiz) - context["quiz_id"]=quiz_id + context["quiz_id"] = quiz_id context["form"] = form return my_render_to_response('yaksh/add_quiz.html', context, @@ -268,7 +268,9 @@ def show_all_questionpapers(request, questionpaper_id=None): return my_render_to_response('yaksh/showquestionpapers.html', context, context_instance=ci) else: - qu_papers = QuestionPaper.objects.get(id=questionpaper_id,is_trial=False) + qu_papers = QuestionPaper.objects.get(id=questionpaper_id, + is_trial=False + ) quiz = qu_papers.quiz fixed_questions = qu_papers.fixed_questions.all() random_questions = qu_papers.random_questions.all() @@ -285,8 +287,8 @@ rights/permissions and log in.""" user = request.user if user.is_authenticated() and is_moderator(user): question_papers = QuestionPaper.objects.filter(quiz__course__creator=user, - quiz__is_trial=False - ) + quiz__is_trial=False + ) trial_course = Course.objects.delete_all_trial_courses(user) trial_quiz = Quiz.objects.delete_all_trial_quizzes(user) users_per_paper = [] @@ -346,14 +348,14 @@ def start(request, questionpaper_id=None, attempt_num=None): msg = 'Quiz not found, please contact your '\ 'instructor/administrator. Please login again thereafter.' return complete(request, msg, attempt_num, questionpaper_id=None) - if not quest_paper.quiz.course.is_enrolled(user) : + if not quest_paper.quiz.course.is_enrolled(user): raise Http404('You are not allowed to view this page!') # prerequisite check and passing criteria if quest_paper.quiz.is_expired(): if is_moderator(user): return redirect("/exam/manage") return redirect("/exam/quizzes") - if quest_paper.quiz.has_prerequisite() and not quest_paper.is_prerequisite_passed(user): + if quest_paper.quiz.has_prerequisite() and not quest_paper.is_prerequisite_passed(user): return redirect("/exam/quizzes") # if any previous attempt last_attempt = AnswerPaper.objects.get_user_last_attempt( @@ -736,10 +738,10 @@ def monitor(request, questionpaper_id=None): raise Http404('You are not allowed to view this page!') if questionpaper_id is None: - q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user) - | Q(quiz__course__teachers=user), - quiz__course__is_trial=False - ).distinct() + q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user) | + Q(quiz__course__teachers=user), + quiz__course__is_trial=False + ).distinct() context = {'papers': [], 'quiz': None, 'quizzes': q_paper} @@ -747,9 +749,10 @@ def monitor(request, questionpaper_id=None): context_instance=ci) # quiz_id is not None. try: - q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user)| - Q(quiz__course__teachers=user), quiz__course__is_trial=False, - id=questionpaper_id).distinct() + q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user) | + Q(quiz__course__teachers=user), + quiz__course__is_trial=False, + id=questionpaper_id).distinct() except QuestionPaper.DoesNotExist: papers = [] q_paper = None @@ -849,7 +852,7 @@ def show_all_questions(request): else: msg = "Please select atleast one question" context['msg'] = msg - + if request.POST.get('test') == 'test': question_ids = request.POST.getlist("question") trial_paper = test_mode(user, "test_questions", question_ids, None) @@ -857,7 +860,6 @@ def show_all_questions(request): trial_paper.save() return my_redirect("/exam/start/1/{0}".format(trial_paper.id)) - questions = Question.objects.filter(user_id=user.id) form = QuestionFilterForm(user=user) upload_form = UploadFileForm() @@ -939,14 +941,15 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): ci = RequestContext(request) if not current_user.is_authenticated() or not is_moderator(current_user): raise Http404('You are not allowed to view this page!') - course_details = Course.objects.filter(Q(creator=current_user)| - Q(teachers=current_user), is_trial=False).distinct() + course_details = Course.objects.filter(Q(creator=current_user) | + Q(teachers=current_user), + is_trial=False).distinct() context = {"course_details": course_details} if quiz_id is not None: questionpaper_id = QuestionPaper.objects.filter(quiz_id=quiz_id)\ .values("id") - user_details = AnswerPaper.objects.get_users_for_questionpaper\ - (questionpaper_id) + user_details = AnswerPaper.objects\ + .get_users_for_questionpaper(questionpaper_id) context = {"users": user_details, "quiz_id": quiz_id} if user_id is not None: @@ -1193,33 +1196,37 @@ def remove_teachers(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - course = get_object_or_404(Course, creator=user, pk=course_id, is_trial=False) + course = get_object_or_404(Course, creator=user, + pk=course_id, is_trial=False + ) if request.method == "POST": teacher_ids = request.POST.getlist('remove') teachers = User.objects.filter(id__in=teacher_ids) course.remove_teachers(*teachers) return my_redirect('/exam/manage/courses') + def test_mode(user, mode, questions_list=None, quiz_id=None): """creates a trial question paper for the moderators""" if questions_list is not None and mode == "test_questions": trial_course = Course.objects.create_trial_course(user) - trial_quiz = Quiz.objects.create_trial_quiz(trial_course,user) + trial_quiz = Quiz.objects.create_trial_quiz(trial_course, user) trial_questionpaper = QuestionPaper.objects\ - .create_trial_paper_to_test_questions\ - (trial_quiz, questions_list) + .create_trial_paper_to_test_questions\ + (trial_quiz, questions_list) else: trial_quiz = Quiz.objects.create_trial_from_quiz(quiz_id, user, mode) trial_questionpaper = QuestionPaper.objects\ - .create_trial_paper_to_test_quiz\ - (trial_quiz, quiz_id) + .create_trial_paper_to_test_quiz\ + (trial_quiz, quiz_id) return trial_questionpaper + @login_required -def test_quiz(request, mode,quiz_id): +def test_quiz(request, mode, quiz_id): """creates a trial quiz for the moderators""" current_user = request.user trial_questionpaper = test_mode(current_user, mode, None, quiz_id) - return my_redirect("/exam/start/{0}".format(trial_questionpaper.id)) \ No newline at end of file + return my_redirect("/exam/start/{0}".format(trial_questionpaper.id)) -- cgit From 8055dc6c13aabaa5caaa16b5ec4b2e07bb4b5b2a Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 1 Jun 2016 00:33:01 +0530 Subject: removed some is_trial parameter --- yaksh/views.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 56e66e0..38d2a79 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -268,9 +268,7 @@ def show_all_questionpapers(request, questionpaper_id=None): return my_render_to_response('yaksh/showquestionpapers.html', context, context_instance=ci) else: - qu_papers = QuestionPaper.objects.get(id=questionpaper_id, - is_trial=False - ) + qu_papers = QuestionPaper.objects.get(id=questionpaper_id) quiz = qu_papers.quiz fixed_questions = qu_papers.fixed_questions.all() random_questions = qu_papers.random_questions.all() @@ -595,7 +593,7 @@ def add_course(request): def enroll_request(request, course_id): user = request.user ci = RequestContext(request) - course = get_object_or_404(Course, pk=course_id, is_trial=False) + course = get_object_or_404(Course, pk=course_id) course.request(user) return my_redirect('/exam/manage/') @@ -604,7 +602,7 @@ def enroll_request(request, course_id): def self_enroll(request, course_id): user = request.user ci = RequestContext(request) - course = get_object_or_404(Course, pk=course_id, is_trial=False) + course = get_object_or_404(Course, pk=course_id) if course.is_self_enroll(): was_rejected = False course.enroll(was_rejected, user) @@ -630,7 +628,7 @@ def course_detail(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id, is_trial=False) + course = get_object_or_404(Course, pk=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -645,7 +643,7 @@ def enroll(request, course_id, user_id=None, was_rejected=False): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id, is_trial=False) + course = get_object_or_404(Course, pk=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -668,7 +666,7 @@ def reject(request, course_id, user_id=None, was_enrolled=False): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id, is_trial=False) + course = get_object_or_404(Course, pk=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -690,7 +688,7 @@ def toggle_course_status(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id, is_trial=False) + course = get_object_or_404(Course, pk=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -855,7 +853,7 @@ def show_all_questions(request): if request.POST.get('test') == 'test': question_ids = request.POST.getlist("question") - trial_paper = test_mode(user, "test_questions", question_ids, None) + trial_paper = test_mode(user, False, question_ids, None) trial_paper.update_total_marks() trial_paper.save() return my_redirect("/exam/start/1/{0}".format(trial_paper.id)) @@ -891,7 +889,7 @@ def download_csv(request, questionpaper_id): user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') - quiz = Quiz.objects.get(questionpaper=questionpaper_id,is_trial=False) + quiz = Quiz.objects.get(questionpaper=questionpaper_id) if not quiz.course.is_creator(user) and not quiz.course.is_teacher(user): raise Http404('The question paper does not belong to your course') @@ -1125,7 +1123,7 @@ def search_teacher(request, course_id): raise Http404('You are not allowed to view this page!') context = {} - course = get_object_or_404(Course, creator=user, pk=course_id, is_trial=False) + course = get_object_or_404(Course, creator=user, pk=course_id) context['course'] = course if request.method == 'POST': @@ -1157,7 +1155,7 @@ def add_teacher(request, course_id): raise Http404('You are not allowed to view this page!') context = {} - course = get_object_or_404(Course, creator=user, pk=course_id, is_trial=False) + course = get_object_or_404(Course, creator=user, pk=course_id) context['course'] = course if request.method == 'POST': @@ -1183,7 +1181,7 @@ def allotted_courses(request): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - courses = Course.objects.filter(teachers=user, is_trial=False) + courses = Course.objects.filter(teachers=user) return my_render_to_response('yaksh/courses.html', {'courses': courses}, context_instance=ci) @@ -1196,9 +1194,7 @@ def remove_teachers(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - course = get_object_or_404(Course, creator=user, - pk=course_id, is_trial=False - ) + course = get_object_or_404(Course, creator=user, pk=course_id) if request.method == "POST": teacher_ids = request.POST.getlist('remove') teachers = User.objects.filter(id__in=teacher_ids) @@ -1206,27 +1202,27 @@ def remove_teachers(request, course_id): return my_redirect('/exam/manage/courses') -def test_mode(user, mode, questions_list=None, quiz_id=None): +def test_mode(user, godmode=False, questions_list=None, quiz_id=None): """creates a trial question paper for the moderators""" - if questions_list is not None and mode == "test_questions": + if questions_list is not None: trial_course = Course.objects.create_trial_course(user) trial_quiz = Quiz.objects.create_trial_quiz(trial_course, user) trial_questionpaper = QuestionPaper.objects\ .create_trial_paper_to_test_questions\ (trial_quiz, questions_list) else: - trial_quiz = Quiz.objects.create_trial_from_quiz(quiz_id, user, mode) + trial_quiz = Quiz.objects.create_trial_from_quiz(quiz_id, user, godmode) trial_questionpaper = QuestionPaper.objects\ .create_trial_paper_to_test_quiz\ - (trial_quiz, quiz_id) + (trial_quiz, quiz_id) return trial_questionpaper @login_required def test_quiz(request, mode, quiz_id): """creates a trial quiz for the moderators""" - + godmode = True if mode == "godmode" else False current_user = request.user - trial_questionpaper = test_mode(current_user, mode, None, quiz_id) + trial_questionpaper = test_mode(current_user, godmode, None, quiz_id) return my_redirect("/exam/start/{0}".format(trial_questionpaper.id)) -- cgit From bb2fbbb66c7548eb6df8ebd65b9db2c0d56f359c Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 1 Jun 2016 00:35:34 +0530 Subject: changed mode argument to bool type --- yaksh/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index ec9a84b..015916d 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -314,7 +314,7 @@ class QuizManager(models.Manager): ) return trial_quiz - def create_trial_from_quiz(self, original_quiz_id, user, mode): + def create_trial_from_quiz(self, original_quiz_id, user, godmode): """Creates a trial quiz from existing quiz""" trial_quiz = self.get(id=original_quiz_id) trial_quiz.course.enroll(False, user) @@ -323,7 +323,7 @@ class QuizManager(models.Manager): trial_quiz.is_trial = True trial_quiz.time_between_attempts = 0 trial_quiz.prerequisite = None - if mode == "godmode": + if godmode: trial_quiz.duration = 1000 trial_quiz.active = True trial_quiz.start_date_time = datetime.now() @@ -460,8 +460,6 @@ class QuestionPaper(models.Model): # Total marks for the question paper. total_marks = models.FloatField() -# is_trial = models.BooleanField(default=False) - objects = QuestionPaperManager() def update_total_marks(self): -- cgit From 46c04c3cdd7c7cdb5acd9d8495934df26f469146 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 1 Jun 2016 00:35:45 +0530 Subject: changed mode argument to bool type --- yaksh/tests.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'yaksh') diff --git a/yaksh/tests.py b/yaksh/tests.py index 71da672..a5b02a6 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -202,7 +202,7 @@ class QuizTestCases(unittest.TestCase): """Test to check if a copy of original quiz is created in godmode""" trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id, self.creator, - "godmode" + True ) self.assertEqual(trial_quiz.description, "demo quiz_trial") self.assertTrue(trial_quiz.is_trial) @@ -217,7 +217,7 @@ class QuizTestCases(unittest.TestCase): """Test to check if a copy of original quiz is created in usermode""" trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id, self.creator, - "usermode" + False ) self.assertEqual(trial_quiz.description, "demo quiz_trial") self.assertTrue(trial_quiz.is_trial) @@ -234,7 +234,7 @@ class QuizTestCases(unittest.TestCase): def test_delete_all_trial_quizzes_creator(self): Quiz.objects.create_trial_from_quiz(self.quiz1.id, self.creator, - "godmode" + True ) Quiz.objects.delete_all_trial_quizzes(self.creator) self.assertFalse(Quiz.objects.filter(course__creator=self.creator, @@ -245,7 +245,7 @@ class QuizTestCases(unittest.TestCase): self.trial_course.add_teachers(self.teacher) Quiz.objects.create_trial_from_quiz(self.quiz1.id, self.creator, - "godmode" + True ) Quiz.objects.delete_all_trial_quizzes(self.teacher) self.assertFalse(Quiz.objects.filter(course__teachers=self.teacher, -- cgit From 1276c2840c3c7f7521c98574dea302160611f79d Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 5 Jul 2016 15:18:12 +0530 Subject: moderator can now select and delete trial papers --- yaksh/models.py | 63 +++++++++++++++++++++------------------------ yaksh/templates/manage.html | 15 +++++++++++ yaksh/tests.py | 41 +++++------------------------ yaksh/views.py | 38 +++++++++++++++++++-------- 4 files changed, 79 insertions(+), 78 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 015916d..f1b0d33 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -69,11 +69,6 @@ class CourseManager(models.Manager): trial_course.enroll(False, user) return trial_course - def delete_all_trial_courses(self, user): - """Deletes all trial course for a user.""" - trial_course = self.filter(creator=user, is_trial=True) - trial_course.delete() - ############################################################################### class Course(models.Model): @@ -316,28 +311,27 @@ class QuizManager(models.Manager): def create_trial_from_quiz(self, original_quiz_id, user, godmode): """Creates a trial quiz from existing quiz""" - trial_quiz = self.get(id=original_quiz_id) - trial_quiz.course.enroll(False, user) - trial_quiz.pk = None - trial_quiz.description += "_trial" - trial_quiz.is_trial = True - trial_quiz.time_between_attempts = 0 - trial_quiz.prerequisite = None - if godmode: - trial_quiz.duration = 1000 - trial_quiz.active = True - trial_quiz.start_date_time = datetime.now() - trial_quiz.end_date_time = datetime(2199, 1, 1, 0, 0, 0, 0) - trial_quiz.save() + trial_quiz_name = "trial_orig_id_{0}".format(original_quiz_id) + + if self.filter(description=trial_quiz_name).exists() and not godmode: + trial_quiz = self.get(description=trial_quiz_name) + + else: + trial_quiz = self.get(id=original_quiz_id) + trial_quiz.course.enroll(False, user) + trial_quiz.pk = None + trial_quiz.description = trial_quiz_name + trial_quiz.is_trial = True + trial_quiz.time_between_attempts = 0 + trial_quiz.prerequisite = None + if godmode: + trial_quiz.duration = 1000 + trial_quiz.active = True + trial_quiz.start_date_time = timezone.now() + trial_quiz.end_date_time = datetime(2199, 1, 1, 0, 0, 0, 0) + trial_quiz.save() return trial_quiz - def delete_all_trial_quizzes(self, user): - trial_quiz = self.filter(Q(course__creator=user) | - Q(course__teachers=user), is_trial=True - ) - trial_quiz.delete() - - ############################################################################### class Quiz(models.Model): """A quiz that students will participate in. One can think of this @@ -430,14 +424,17 @@ class QuestionPaperManager(models.Manager): def create_trial_paper_to_test_quiz(self, trial_quiz, original_quiz_id): """Creates a trial question paper to test quiz.""" - trial_questionpaper, trial_questions = self._create_trial_from_questionpaper\ - (original_quiz_id) - trial_questionpaper.quiz = trial_quiz - trial_questionpaper.fixed_questions\ - .add(*trial_questions["fixed_questions"]) - trial_questionpaper.random_questions\ - .add(*trial_questions["random_questions"]) - trial_questionpaper.save() + if self.filter(quiz=trial_quiz).exists(): + trial_questionpaper = self.get(quiz=trial_quiz) + else: + trial_questionpaper, trial_questions = self._create_trial_from_questionpaper\ + (original_quiz_id) + trial_questionpaper.quiz = trial_quiz + trial_questionpaper.fixed_questions\ + .add(*trial_questions["fixed_questions"]) + trial_questionpaper.random_questions\ + .add(*trial_questions["random_questions"]) + trial_questionpaper.save() return trial_questionpaper diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html index 4b9e2ba..334f6a2 100644 --- a/yaksh/templates/manage.html +++ b/yaksh/templates/manage.html @@ -77,6 +77,21 @@
Click on the button given below to add a new course.
+ {% if trial_quiz %} +
You have trial papers. + + + {% csrf_token %} + {% for quiz in trial_quiz %} + + + + + {% endfor %} +
{{quiz.description}}
+
+ + {% endif %} {% endblock %} diff --git a/yaksh/tests.py b/yaksh/tests.py index a5b02a6..bf3be04 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -204,7 +204,7 @@ class QuizTestCases(unittest.TestCase): self.creator, True ) - self.assertEqual(trial_quiz.description, "demo quiz_trial") + self.assertEqual(trial_quiz.description, "trial_orig_id_1") self.assertTrue(trial_quiz.is_trial) self.assertEqual(trial_quiz.duration, 1000) self.assertTrue(trial_quiz.active) @@ -215,43 +215,22 @@ class QuizTestCases(unittest.TestCase): def test_create_trial_from_quiz_usermode(self): """Test to check if a copy of original quiz is created in usermode""" - trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id, + trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz2.id, self.creator, False ) - self.assertEqual(trial_quiz.description, "demo quiz_trial") + self.assertEqual(trial_quiz.description, "trial_orig_id_2") self.assertTrue(trial_quiz.is_trial) - self.assertEqual(trial_quiz.duration, self.quiz1.duration) - self.assertEqual(trial_quiz.active, self.quiz1.active) + self.assertEqual(trial_quiz.duration, self.quiz2.duration) + self.assertEqual(trial_quiz.active, self.quiz2.active) self.assertEqual(trial_quiz.start_date_time, - self.quiz1.start_date_time + self.quiz2.start_date_time ) self.assertEqual(trial_quiz.end_date_time, - self.quiz1.end_date_time + self.quiz2.end_date_time ) self.assertEqual(trial_quiz.time_between_attempts, 0) - def test_delete_all_trial_quizzes_creator(self): - Quiz.objects.create_trial_from_quiz(self.quiz1.id, - self.creator, - True - ) - Quiz.objects.delete_all_trial_quizzes(self.creator) - self.assertFalse(Quiz.objects.filter(course__creator=self.creator, - is_trial=True).exists() - ) - - def test_delete_all_trial_quizzes_added_teacher(self): - self.trial_course.add_teachers(self.teacher) - Quiz.objects.create_trial_from_quiz(self.quiz1.id, - self.creator, - True - ) - Quiz.objects.delete_all_trial_quizzes(self.teacher) - self.assertFalse(Quiz.objects.filter(course__teachers=self.teacher, - is_trial=True).exists() - ) - ############################################################################### class QuestionPaperTestCases(unittest.TestCase): @@ -611,12 +590,6 @@ class CourseTestCases(unittest.TestCase): ) self.assertTrue(trial_course.is_trial) - def test_delete_all_trial_courses(self): - Course.objects.create_trial_course(self.creator) - Course.objects.delete_all_trial_courses(self.creator) - self.assertFalse(Course.objects.filter(creator=self.creator, - is_trial=True).exists()) - ############################################################################### class TestCaseTestCases(unittest.TestCase): diff --git a/yaksh/views.py b/yaksh/views.py index 38d2a79..3db51a9 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -283,12 +283,20 @@ def prof_manage(request): """Take credentials of the user with professor/moderator rights/permissions and log in.""" user = request.user + ci = RequestContext(request) if user.is_authenticated() and is_moderator(user): question_papers = QuestionPaper.objects.filter(quiz__course__creator=user, quiz__is_trial=False ) - trial_course = Course.objects.delete_all_trial_courses(user) - trial_quiz = Quiz.objects.delete_all_trial_quizzes(user) + trial_quiz = Quiz.objects.filter(course__creator=user, is_trial=True) + if request.method == "POST": + delete_quiz = request.POST.getlist('delete_quiz') + for quiz_id in delete_quiz: + quiz = Quiz.objects.get(id=quiz_id) + if quiz.course.is_trial == True: + quiz.course.delete() + else: + quiz.delete() users_per_paper = [] for paper in question_papers: answer_papers = AnswerPaper.objects.filter(question_paper=paper) @@ -298,8 +306,10 @@ rights/permissions and log in.""" passed=False).count() temp = paper, answer_papers, users_passed, users_failed users_per_paper.append(temp) - context = {'user': user, 'users_per_paper': users_per_paper} - return my_render_to_response('manage.html', context) + context = {'user': user, 'users_per_paper': users_per_paper, + 'trial_quiz': trial_quiz + } + return my_render_to_response('manage.html', context, context_instance=ci) return my_redirect('/exam/login/') @@ -354,6 +364,8 @@ def start(request, questionpaper_id=None, attempt_num=None): return redirect("/exam/manage") return redirect("/exam/quizzes") if quest_paper.quiz.has_prerequisite() and not quest_paper.is_prerequisite_passed(user): + if is_moderator(user): + return redirect("/exam/manage") return redirect("/exam/quizzes") # if any previous attempt last_attempt = AnswerPaper.objects.get_user_last_attempt( @@ -362,6 +374,8 @@ def start(request, questionpaper_id=None, attempt_num=None): return show_question(request, last_attempt.current_question(), last_attempt) # allowed to start if not quest_paper.can_attempt_now(user): + if is_moderator(user): + return redirect("/exam/manage") return redirect("/exam/quizzes") if attempt_num is None: attempt_number = 1 if not last_attempt else last_attempt.attempt_number +1 @@ -848,15 +862,17 @@ def show_all_questions(request): "{0}_questions.json"'.format(user) return response else: - msg = "Please select atleast one question" - context['msg'] = msg + context['msg'] = "Please select atleast one question to download" if request.POST.get('test') == 'test': question_ids = request.POST.getlist("question") - trial_paper = test_mode(user, False, question_ids, None) - trial_paper.update_total_marks() - trial_paper.save() - return my_redirect("/exam/start/1/{0}".format(trial_paper.id)) + if question_ids: + trial_paper = test_mode(user, False, question_ids, None) + trial_paper.update_total_marks() + trial_paper.save() + return my_redirect("/exam/start/1/{0}".format(trial_paper.id)) + else: + context["msg"] = "Please select atleast one question to test" questions = Question.objects.filter(user_id=user.id) form = QuestionFilterForm(user=user) @@ -1189,7 +1205,7 @@ def allotted_courses(request): @login_required def remove_teachers(request, course_id): """ remove user from a course """ - + user = request.user if not is_moderator(user): raise Http404('You are not allowed to view this page!') -- cgit From 9c61c84194e6b52913dfc284765a7b7bd77201ad Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 5 Jul 2016 17:50:31 +0530 Subject: will not create trial paper object if the quiz has expired or is inactive --- yaksh/models.py | 8 +++++--- yaksh/tests.py | 6 +++--- yaksh/views.py | 4 ++++ 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index f1b0d33..bfe204c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -303,7 +303,7 @@ class QuizManager(models.Manager): """Creates a trial quiz for testing questions""" trial_quiz = self.create(course=trial_course, duration=1000, - description="trial_quiz", + description="trial_questions", is_trial=True, time_between_attempts=0 ) @@ -311,9 +311,11 @@ class QuizManager(models.Manager): def create_trial_from_quiz(self, original_quiz_id, user, godmode): """Creates a trial quiz from existing quiz""" - trial_quiz_name = "trial_orig_id_{0}".format(original_quiz_id) + trial_quiz_name = "Trial_orig_id_{0}_{1}".format(original_quiz_id, + "godmode" if godmode else "usermode" + ) - if self.filter(description=trial_quiz_name).exists() and not godmode: + if self.filter(description=trial_quiz_name).exists(): trial_quiz = self.get(description=trial_quiz_name) else: diff --git a/yaksh/tests.py b/yaksh/tests.py index bf3be04..d5dfb89 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -194,7 +194,7 @@ class QuizTestCases(unittest.TestCase): ) self.assertEqual(trial_quiz.course, self.trial_course) self.assertEqual(trial_quiz.duration, 1000) - self.assertEqual(trial_quiz.description, "trial_quiz") + self.assertEqual(trial_quiz.description, "trial_questions") self.assertTrue(trial_quiz.is_trial) self.assertEqual(trial_quiz.time_between_attempts, 0) @@ -204,7 +204,7 @@ class QuizTestCases(unittest.TestCase): self.creator, True ) - self.assertEqual(trial_quiz.description, "trial_orig_id_1") + self.assertEqual(trial_quiz.description, "Trial_orig_id_1_godmode") self.assertTrue(trial_quiz.is_trial) self.assertEqual(trial_quiz.duration, 1000) self.assertTrue(trial_quiz.active) @@ -219,7 +219,7 @@ class QuizTestCases(unittest.TestCase): self.creator, False ) - self.assertEqual(trial_quiz.description, "trial_orig_id_2") + self.assertEqual(trial_quiz.description, "Trial_orig_id_2_usermode") self.assertTrue(trial_quiz.is_trial) self.assertEqual(trial_quiz.duration, self.quiz2.duration) self.assertEqual(trial_quiz.active, self.quiz2.active) diff --git a/yaksh/views.py b/yaksh/views.py index 3db51a9..ae32bbf 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1240,5 +1240,9 @@ def test_quiz(request, mode, quiz_id): """creates a trial quiz for the moderators""" godmode = True if mode == "godmode" else False current_user = request.user + quiz = Quiz.objects.get(id=quiz_id) + if (quiz.is_expired() or not quiz.active) and not godmode: + return my_redirect('/exam/manage') + trial_questionpaper = test_mode(current_user, godmode, None, quiz_id) return my_redirect("/exam/start/{0}".format(trial_questionpaper.id)) -- cgit