From 848f7945811f1d16bdf8d5e2a99d157d9ed9a18c Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 6 Sep 2016 12:44:49 +0530 Subject: added 'add new quiz' button to each course --- yaksh/views.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 1abf248..0fb2214 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -246,7 +246,7 @@ def edit_question(request, question_id=None): context_instance=ci) @login_required -def add_quiz(request, quiz_id=None): +def add_quiz(request, course_id, quiz_id=None): """To add a new quiz in the database. Create a new quiz and store it.""" user = request.user @@ -256,23 +256,29 @@ def add_quiz(request, quiz_id=None): context = {} if request.method == "POST": if quiz_id is None: - form = QuizForm(request.POST, user=user) + form = QuizForm(request.POST, user=user, course=course_id) if form.is_valid(): form.save() return my_redirect(reverse('yaksh:design_questionpaper')) + else: + context["form"] = form + return my_render_to_response('yaksh/add_quiz.html', + context, + context_instance=ci) else: quiz = Quiz.objects.get(id=quiz_id) - form = QuizForm(request.POST, user=user, instance=quiz) + form = QuizForm(request.POST, user=user, course=course_id, + instance=quiz) if form.is_valid(): form.save() context["quiz_id"] = quiz_id return my_redirect("/exam/manage/") else: if quiz_id is None: - form = QuizForm(user=user) + form = QuizForm(course=course_id, user=user) else: quiz = Quiz.objects.get(id=quiz_id) - form = QuizForm(user=user, instance=quiz) + form = QuizForm(user=user,course=course_id, instance=quiz) context["quiz_id"] = quiz_id context["form"] = form return my_render_to_response('yaksh/add_quiz.html', -- cgit From 8b01d249b7ccdff9d75447a6b12eb96641e795e7 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 6 Sep 2016 15:14:50 +0530 Subject: changed test cases to reflect changes in addquiz view function --- yaksh/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 0fb2214..dcf6133 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -250,8 +250,9 @@ def add_quiz(request, course_id, quiz_id=None): """To add a new quiz in the database. Create a new quiz and store it.""" user = request.user + course = Course.objects.get(id=course_id) ci = RequestContext(request) - if not is_moderator(user): + if not is_moderator(user) or (user != course.creator and user not in course.teachers.all()): raise Http404('You are not allowed to view this page!') context = {} if request.method == "POST": -- cgit From 27720bb67d5c44dcb2d9ec8f315f4e26624c0a4c Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 6 Sep 2016 16:14:08 +0530 Subject: users and not course creator will see their own trial papers --- yaksh/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 1abf248..476ccc6 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -313,7 +313,9 @@ rights/permissions and log in.""" question_papers = QuestionPaper.objects.filter(quiz__course__creator=user, quiz__is_trial=False ) - trial_quiz = Quiz.objects.filter(course__creator=user, is_trial=True) + trial_paper = AnswerPaper.objects.filter(user=user, + question_paper__quiz__is_trial=True + ) if request.method == "POST": delete_quiz = request.POST.getlist('delete_quiz') for quiz_id in delete_quiz: @@ -332,7 +334,7 @@ rights/permissions and log in.""" temp = paper, answer_papers, users_passed, users_failed users_per_paper.append(temp) context = {'user': user, 'users_per_paper': users_per_paper, - 'trial_quiz': trial_quiz + 'trial_paper': trial_paper } return my_render_to_response('manage.html', context, context_instance=ci) return my_redirect('/exam/login/') -- cgit From 7d243a58856c09d7d547c1a239ecb9af56f3d6df Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Tue, 6 Sep 2016 16:16:14 +0530 Subject: modified monitor view function to remove trial paper occurrences --- yaksh/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 476ccc6..f32b8f8 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -791,7 +791,7 @@ def monitor(request, questionpaper_id=None): 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 + quiz__is_trial=False ).distinct() context = {'papers': [], 'quiz': None, @@ -802,7 +802,7 @@ def monitor(request, questionpaper_id=None): try: q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user) | Q(quiz__course__teachers=user), - quiz__course__is_trial=False, + quiz__is_trial=False, id=questionpaper_id).distinct() except QuestionPaper.DoesNotExist: papers = [] -- cgit From 6e2a0db4d67902cca52277d22dd7a67ebd059268 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 7 Sep 2016 16:14:54 +0530 Subject: removed initial form field from QuizForm and minor fixes in add_quiz view function and courses template --- yaksh/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index dcf6133..fa4dac6 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -250,7 +250,7 @@ def add_quiz(request, course_id, quiz_id=None): """To add a new quiz in the database. Create a new quiz and store it.""" user = request.user - course = Course.objects.get(id=course_id) + course = get_object_or_404(Course, pk=course_id) ci = RequestContext(request) if not is_moderator(user) or (user != course.creator and user not in course.teachers.all()): raise Http404('You are not allowed to view this page!') -- cgit From ccea043bde737883063adfaf28eb16c95218d58b Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Wed, 7 Sep 2016 18:19:38 +0530 Subject: only answerpapers are deleted and not the entire trial quiz --- yaksh/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index f32b8f8..7c4e9af 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -318,12 +318,16 @@ rights/permissions and log in.""" ) 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() + for answerpaper_id in delete_quiz: + answerpaper = AnswerPaper.objects.get(id=answerpaper_id) + if answerpaper.question_paper.quiz.course.is_trial == True: + answerpaper.question_paper.quiz.course.delete() else: - quiz.delete() + qpaper = answerpaper.question_paper + if qpaper.answerpaper_set.count() == 1: + answerpaper.question_paper.quiz.delete() + else: + answerpaper.delete() users_per_paper = [] for paper in question_papers: answer_papers = AnswerPaper.objects.filter(question_paper=paper) -- cgit From e423320c4682718cd39d2cfec4e5da59a86c68c0 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 8 Sep 2016 08:05:06 +0530 Subject: changed input name in html from delete_quiz to delete_paper --- yaksh/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 7c4e9af..08320be 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -317,15 +317,15 @@ rights/permissions and log in.""" question_paper__quiz__is_trial=True ) if request.method == "POST": - delete_quiz = request.POST.getlist('delete_quiz') - for answerpaper_id in delete_quiz: + delete_quiz = request.POST.getlist('delete_paper') + for answerpaper_id in delete_paper: answerpaper = AnswerPaper.objects.get(id=answerpaper_id) if answerpaper.question_paper.quiz.course.is_trial == True: answerpaper.question_paper.quiz.course.delete() else: qpaper = answerpaper.question_paper if qpaper.answerpaper_set.count() == 1: - answerpaper.question_paper.quiz.delete() + qpaper.quiz.delete() else: answerpaper.delete() users_per_paper = [] -- cgit From bc8095aaa0fe19da925e244967eb9ae77cf0f970 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Thu, 8 Sep 2016 11:06:39 +0530 Subject: minor variable name changes in views --- yaksh/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 08320be..592dd20 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -317,13 +317,13 @@ rights/permissions and log in.""" question_paper__quiz__is_trial=True ) if request.method == "POST": - delete_quiz = request.POST.getlist('delete_paper') + delete_paper = request.POST.getlist('delete_paper') for answerpaper_id in delete_paper: answerpaper = AnswerPaper.objects.get(id=answerpaper_id) - if answerpaper.question_paper.quiz.course.is_trial == True: - answerpaper.question_paper.quiz.course.delete() + qpaper = answerpaper.question_paper + if qpaper.quiz.course.is_trial == True: + qpaper.quiz.course.delete() else: - qpaper = answerpaper.question_paper if qpaper.answerpaper_set.count() == 1: qpaper.quiz.delete() else: -- cgit