From fbeed0456532b2b36f02a26dbfffc132235d5e4c Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 19 Aug 2013 13:09:10 +0530 Subject: This branch was created for testing the app. Changes made here are during the testing phase. And the feedbacks recevied are implemented. --- testapp/exam/urls.py | 6 +++--- testapp/exam/views.py | 44 +++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 24 deletions(-) (limited to 'testapp/exam') diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index 14aaa8a..33b2edf 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -8,14 +8,14 @@ urlpatterns = patterns('exam.views', url(r'^start/$', 'start'), url(r'^start/(?P\d+)/$','start'), url(r'^quit/(?P\d+)/$', 'quit'), - url(r'^intro/$','start'), + url(r'^intro/(?P\d+)/$','intro'), url(r'^complete/$', 'complete'), url(r'^complete/(?P\d+)/$', 'complete'), url(r'^register/$', 'user_register'), url(r'^(?P\d+)/$', 'question'), url(r'^(?P\d+)/check/$', 'check'), url(r'^(?P\d+)/check/(?P\d+)/$', 'check'), - + url(r'^intro/$', 'start'), url(r'^manage/$', 'prof_manage'), url(r'^manage/addquestion/$', 'add_question'), @@ -32,7 +32,7 @@ urlpatterns = patterns('exam.views', url(r'^manage/showquestionpapers/$','show_all_questionpapers'), url(r'^manage/showquestionpapers/(?P\d+)/$',\ 'show_all_questionpapers'), - url(r'^manage/monitor/(?P\d+)/$', 'monitor'), + url(r'^manage/monitor/(?P\d+)/$', 'monitor'), url(r'^manage/user_data/(?P[a-zA-Z0-9_.]+)/$','user_data'), url(r'^manage/designquestionpaper/$','design_questionpaper'), url(r'^manage/designquestionpaper/(?P\d+)/$',\ diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 2545d8b..f21357e 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -151,6 +151,14 @@ def quizlist_user(request): context = {'quizzes': avail_quiz, 'user': user} return my_render_to_response("exam/quizzes_user.html", context) +def intro(request, questionpaper_id): + """Show introduction page before quiz starts""" + user = request.user + context = {'user': user, 'paper_id': questionpaper_id } + ci = RequestContext(request) + return my_render_to_response('exam/intro.html', context, + context_instance=ci) + def results_user(request): """Show list of Results of Quizzes that is taken by logged-in user.""" @@ -158,7 +166,11 @@ def results_user(request): papers = AnswerPaper.objects.filter(user=user) quiz_marks = [] for paper in papers: - temp = paper.question_paper.quiz.description, paper.get_total_marks() + marks_obtained = paper.get_total_marks() + max_marks = paper.question_paper.total_marks + percentage = round((marks_obtained/max_marks)*100,2) + temp = paper.question_paper.quiz.description, marks_obtained,\ + max_marks, percentage quiz_marks.append(temp) context = {'papers': quiz_marks} return my_render_to_response("exam/results_user.html", context) @@ -653,16 +665,9 @@ def start(request, questionpaper_id=None): questions = [str(_.id) for _ in questionpaper.questions.all()] random.shuffle(questions) - #questions = questionpaper.questions - #random.shuffle(questions) new_paper.questions = "|".join(questions) new_paper.save() - # Show the user the intro page. - context = {'user': user, 'paper_id': questionpaper_id} - ci = RequestContext(request) - return my_render_to_response('exam/intro.html', context, - context_instance=ci) - + return start(request, questionpaper_id) def question(request, q_id, questionpaper_id,success_msg=None): """Check the credentials of the user and start the exam.""" @@ -680,7 +685,9 @@ def question(request, q_id, questionpaper_id,success_msg=None): if not paper.question_paper.quiz.active: reason='The quiz has been deactivated!' return complete(request, reason, questionpaper_id) - + #if new: + # paper.start_time = datetime.datetime.now() + # paper.end_time = datetime.datetime.now() time_left = paper.time_left() if time_left == 0: return complete(request, reason='Your time is up!') @@ -731,7 +738,6 @@ def check(request, q_id, questionpaper_id=None): if question.type == 'mcq': # Add the answer submitted, regardless of it being correct or not. if user_answer is not None : - print "EEERRRROOOORRRRRRR :P" new_answer = Answer(question=question, answer=user_answer, correct=False) new_answer.save() @@ -790,13 +796,9 @@ def check(request, q_id, questionpaper_id=None): context_instance=ci) else: if time_left <= 0: - print "success" - print str(time_left) reason='Your time is up!' return complete(request, reason, questionpaper_id) else: - print "fail" - print time_left next_q = paper.completed_question(question.id) return show_question(request, next_q, questionpaper_id,success_msg) @@ -850,14 +852,14 @@ def complete(request, reason=None, questionpaper_id=None): return my_redirect('/exam/') -def monitor(request, quiz_id=None): +def monitor(request, questionpaper_id=None): """Monitor the progress of the papers taken so far.""" user = request.user if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') - if quiz_id is None: + if questionpaper_id is None: q_paper = QuestionPaper.objects.all() context = {'papers': [], 'quiz': None, @@ -866,15 +868,15 @@ def monitor(request, quiz_id=None): context_instance=RequestContext(request)) # quiz_id is not None. try: - quiz = QuestionPaper.objects.get(id=quiz_id) + q_paper = QuestionPaper.objects.get(id=questionpaper_id) except QuestionPaper.DoesNotExist: papers = [] - quiz = None + q_paper = None else: - papers = AnswerPaper.objects.all().annotate( + papers = AnswerPaper.objects.filter(question_paper=q_paper).annotate( total=Sum('answers__marks')).order_by('-total') - context = {'papers': papers, 'quiz': quiz, 'quizzes': None} + context = {'papers': papers, 'quiz': q_paper, 'quizzes': None} return my_render_to_response('exam/monitor.html', context, context_instance=RequestContext(request)) -- cgit