From b9c884f370d08654c418b7cbd010f3c61870b193 Mon Sep 17 00:00:00 2001 From: Parth buch Date: Tue, 13 Mar 2012 15:19:35 +0530 Subject: Updated production.py to close the issue#3 --- testapp/production.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'testapp') diff --git a/testapp/production.py b/testapp/production.py index 2710bdb..be3d200 100644 --- a/testapp/production.py +++ b/testapp/production.py @@ -1,10 +1,14 @@ -from project.settings import * +from testapp.settings import * DEBUG=False TEMPLATE_DEBUG=DEBUG -DATABASE_ENGINE = 'django.db.backends.mysql' -DATABASE_NAME = 'online_test' -DATABASE_USER = 'online_test_user' + +DATABASES["default"]["ENGINE"] = 'django.db.backends.mysql' +DATABASES["default"]["NAME"] = 'online_test' +DATABASES["default"]["USER"] = 'online_test_user' + +from testapp.local import DATABASE_PASSWORD # Imports DATABASE_PASSWORD from testapp/local.py that is not part of git repo -from testapp.local import DATABASE_PASSWORD \ No newline at end of file +DATABASES["default"]["PASSWORD"] = DATABASE_PASSWORD + -- cgit From 88963ad2a4991260ea106d18bea55ad019446b4c Mon Sep 17 00:00:00 2001 From: Parth Buch Date: Fri, 20 Jul 2012 16:13:10 +0530 Subject: Removed the database settings from production.py, now relies on local.py --- testapp/production.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'testapp') diff --git a/testapp/production.py b/testapp/production.py index be3d200..f4d88e2 100644 --- a/testapp/production.py +++ b/testapp/production.py @@ -2,13 +2,5 @@ from testapp.settings import * DEBUG=False TEMPLATE_DEBUG=DEBUG - - -DATABASES["default"]["ENGINE"] = 'django.db.backends.mysql' -DATABASES["default"]["NAME"] = 'online_test' -DATABASES["default"]["USER"] = 'online_test_user' - -from testapp.local import DATABASE_PASSWORD -# Imports DATABASE_PASSWORD from testapp/local.py that is not part of git repo -DATABASES["default"]["PASSWORD"] = DATABASE_PASSWORD +from testapp.local import * -- cgit From 2e2123067d2477602d5e05fab02b7d36396f2d1f Mon Sep 17 00:00:00 2001 From: Hardik Ghaghada Date: Tue, 4 Jun 2013 12:47:17 +0530 Subject: Corrected a syntax error at line 479 --- testapp/exam/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testapp') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 5a5f5fe..1d5d6f6 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -476,7 +476,7 @@ def automatic_questionpaper(request, questionpaper_id=None): context = {'data': {'questions': fetched_questions, 'tags': tags, 'msg': msg}} - return my_render_to_response\( + return my_render_to_response( 'exam/automatic_questionpaper.html', context, context_instance=RequestContext(request)) else: -- cgit From 77321c3590301a8550b8b351b6e8bbb382dc8947 Mon Sep 17 00:00:00 2001 From: Hardik Ghaghada Date: Mon, 1 Jul 2013 12:48:12 +0530 Subject: made changes as per the comments on pull request --- testapp/exam/views.py | 11 +++--- testapp/static/exam/js/add_question.js | 65 +++++++++++++++++----------------- 2 files changed, 38 insertions(+), 38 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 6c977ee..4956f84 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -695,16 +695,15 @@ def check(request, q_id, questionpaper_id=None): # Add the answer submitted, regardless of it being correct or not. new_answer = Answer(question=question, answer=user_answer, correct=False) - new_answer.save() - paper.answers.add(new_answer) + else: - """Add the answer submitted with the Snippet code, - regardless of it being correct or not.""" + # Add the answer submitted with the Snippet code (correct or incorrect) answer_check = snippet_code + "\n" + user_answer new_answer = Answer(question=question, answer=answer_check, correct=False) - new_answer.save() - paper.answers.add(new_answer) + + new_answer.save() + paper.answers.add(new_answer) # If we were not skipped, we were asked to check. For any non-mcq # questions, we obtain the results via XML-RPC with the code executed diff --git a/testapp/static/exam/js/add_question.js b/testapp/static/exam/js/add_question.js index ab27dc0..d990291 100644 --- a/testapp/static/exam/js/add_question.js +++ b/testapp/static/exam/js/add_question.js @@ -26,16 +26,16 @@ function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { - input.focus(); - input.setSelectionRange(selectionStart, selectionEnd); + input.focus(); + input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { - var range = input.createTextRange(); - range.collapse(true); - range.moveEnd('character', selectionEnd); - range.moveStart('character', selectionStart); - range.select(); + var range = input.createTextRange(); + range.collapse(true); + range.moveEnd('character', selectionEnd); + range.moveStart('character', selectionStart); + range.select(); } } @@ -43,31 +43,31 @@ function replaceSelection (input, replaceString) { if (input.setSelectionRange) { - var selectionStart = input.selectionStart; - var selectionEnd = input.selectionEnd; - input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd); - if (selectionStart != selectionEnd) - { - setSelectionRange(input, selectionStart, selectionStart + replaceString.length); - } - else - { - setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length); - } + var selectionStart = input.selectionStart; + var selectionEnd = input.selectionEnd; + input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd); + if (selectionStart != selectionEnd) + { + setSelectionRange(input, selectionStart, selectionStart + replaceString.length); + } + else + { + setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length); + } } else if (document.selection) { - var range = document.selection.createRange(); - if (range.parentElement() == input) - { - var isCollapsed = range.text == ''; - range.text = replaceString; - if (!isCollapsed) - { - range.moveStart('character', -replaceString.length); - range.select(); - } - } + var range = document.selection.createRange(); + if (range.parentElement() == input) + { + var isCollapsed = range.text == ''; + range.text = replaceString; + if (!isCollapsed) + { + range.moveStart('character', -replaceString.length); + range.select(); + } + } } } @@ -97,7 +97,8 @@ function textareaformat() setTimeout(document.getElementById('id_snippet'),0); return false; } - }); + }); + $('#id_description').bind('focus', function( event ){ document.getElementById("id_description").rows=5; document.getElementById("id_description").cols=40; @@ -121,21 +122,21 @@ function textareaformat() document.getElementById("id_test").rows=1; document.getElementById("id_test").cols=40; }); + $('#id_options').bind('focus', function( event ){ document.getElementById("id_options").rows=5; document.getElementById("id_options").cols=40; }); - $('#id_options').bind('blur', function( event ){ document.getElementById("id_options").rows=1; document.getElementById("id_options").cols=40; }); + $('#id_snippet').bind('focus', function( event ){ document.getElementById("id_snippet").rows=5; document.getElementById("id_snippet").cols=40; $('#id_snippet').val(""); }); - $('#id_snippet').bind('blur', function( event ){ document.getElementById("id_snippet").rows=1; document.getElementById("id_snippet").cols=40; -- cgit From b045c38d01685a9bb2183cd7a1a3b59cc410a0b4 Mon Sep 17 00:00:00 2001 From: Hardik Ghaghada Date: Mon, 1 Jul 2013 16:53:38 +0530 Subject: corrected indentation in all js files --- testapp/static/exam/js/edit_question.js | 70 ++++++++++++++++----------------- testapp/static/exam/js/question.js | 68 ++++++++++++++++---------------- testapp/static/exam/js/show_quiz.js | 2 - 3 files changed, 69 insertions(+), 71 deletions(-) (limited to 'testapp') diff --git a/testapp/static/exam/js/edit_question.js b/testapp/static/exam/js/edit_question.js index 023b654..8866b9a 100644 --- a/testapp/static/exam/js/edit_question.js +++ b/testapp/static/exam/js/edit_question.js @@ -50,16 +50,16 @@ function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { - input.focus(); - input.setSelectionRange(selectionStart, selectionEnd); + input.focus(); + input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { - var range = input.createTextRange(); - range.collapse(true); - range.moveEnd('character', selectionEnd); - range.moveStart('character', selectionStart); - range.select(); + var range = input.createTextRange(); + range.collapse(true); + range.moveEnd('character', selectionEnd); + range.moveStart('character', selectionStart); + range.select(); } } @@ -67,31 +67,31 @@ function replaceSelection (input, replaceString) { if (input.setSelectionRange) { - var selectionStart = input.selectionStart; - var selectionEnd = input.selectionEnd; - input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd); - if (selectionStart != selectionEnd) - { - setSelectionRange(input, selectionStart, selectionStart + replaceString.length); - } - else - { - setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length); - } + var selectionStart = input.selectionStart; + var selectionEnd = input.selectionEnd; + input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd); + if (selectionStart != selectionEnd) + { + setSelectionRange(input, selectionStart, selectionStart + replaceString.length); + } + else + { + setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length); + } } else if (document.selection) { - var range = document.selection.createRange(); - if (range.parentElement() == input) - { - var isCollapsed = range.text == ''; - range.text = replaceString; - if (!isCollapsed) - { - range.moveStart('character', -replaceString.length); - range.select(); - } - } + var range = document.selection.createRange(); + if (range.parentElement() == input) + { + var isCollapsed = range.text == ''; + range.text = replaceString; + if (!isCollapsed) + { + range.moveStart('character', -replaceString.length); + range.select(); + } + } } } @@ -104,7 +104,7 @@ function data(showContent,showHideDiv,a,summary) { con.style.display = "none" ele.style.display = "none"; - atag.text = summary; + atag.text = summary; } else { @@ -183,17 +183,17 @@ function catchTab(item,e) { if(navigator.userAgent.match("Gecko")) { - c=e.which; + c=e.which; } else { - c=e.keyCode; + c=e.keyCode; } if(c==9) { - replaceSelection(item,String.fromCharCode(9)); - setTimeout("document.getElementById('"+item.id+"').focus();",0); - return false; + replaceSelection(item,String.fromCharCode(9)); + setTimeout("document.getElementById('"+item.id+"').focus();",0); + return false; } } diff --git a/testapp/static/exam/js/question.js b/testapp/static/exam/js/question.js index dc37ea4..cb6807e 100644 --- a/testapp/static/exam/js/question.js +++ b/testapp/static/exam/js/question.js @@ -13,16 +13,16 @@ function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { - input.focus(); - input.setSelectionRange(selectionStart, selectionEnd); + input.focus(); + input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { - var range = input.createTextRange(); - range.collapse(true); - range.moveEnd('character', selectionEnd); - range.moveStart('character', selectionStart); - range.select(); + var range = input.createTextRange(); + range.collapse(true); + range.moveEnd('character', selectionEnd); + range.moveStart('character', selectionStart); + range.select(); } } @@ -30,31 +30,31 @@ function replaceSelection (input, replaceString) { if (input.setSelectionRange) { - var selectionStart = input.selectionStart; - var selectionEnd = input.selectionEnd; - input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd); - if (selectionStart != selectionEnd) - { - setSelectionRange(input, selectionStart, selectionStart + replaceString.length); - } - else - { - setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length); - } + var selectionStart = input.selectionStart; + var selectionEnd = input.selectionEnd; + input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd); + if (selectionStart != selectionEnd) + { + setSelectionRange(input, selectionStart, selectionStart + replaceString.length); + } + else + { + setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length); + } } else if (document.selection) { - var range = document.selection.createRange(); - if (range.parentElement() == input) - { - var isCollapsed = range.text == ''; - range.text = replaceString; - if (!isCollapsed) - { - range.moveStart('character', -replaceString.length); - range.select(); - } - } + var range = document.selection.createRange(); + if (range.parentElement() == input) + { + var isCollapsed = range.text == ''; + range.text = replaceString; + if (!isCollapsed) + { + range.moveStart('character', -replaceString.length); + range.select(); + } + } } } @@ -62,17 +62,17 @@ function catchTab(item,e) { if(navigator.userAgent.match("Gecko")) { - c=e.which; + c=e.which; } else { - c=e.keyCode; + c=e.keyCode; } if(c==9) { - replaceSelection(item,String.fromCharCode(9)); - setTimeout("document.getElementById('"+item.id+"').focus();",0); - return false; + replaceSelection(item,String.fromCharCode(9)); + setTimeout("document.getElementById('"+item.id+"').focus();",0); + return false; } } diff --git a/testapp/static/exam/js/show_quiz.js b/testapp/static/exam/js/show_quiz.js index 2e6e2de..c58feaa 100644 --- a/testapp/static/exam/js/show_quiz.js +++ b/testapp/static/exam/js/show_quiz.js @@ -38,6 +38,4 @@ function confirm_edit(frm) } else return true; - - } -- cgit From c734fe4710c6e2240f02626288fbc6b915ab29dd Mon Sep 17 00:00:00 2001 From: Hardik Ghaghada Date: Tue, 2 Jul 2013 17:36:21 +0530 Subject: edited views & model to congrtulate student & corrected indentation at various places --- testapp/exam/models.py | 1 + testapp/exam/views.py | 259 +++++++++++++++++++++++++++++-------------------- 2 files changed, 156 insertions(+), 104 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/models.py b/testapp/exam/models.py index 00d32e4..da9bc0a 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -113,6 +113,7 @@ class Quiz(models.Model): class QuestionPaper(models.Model): quiz = models.ForeignKey(Quiz) questions = models.ManyToManyField(Question) + total_marks = models.FloatField() ################################################################################ class AnswerPaper(models.Model): diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 4c47004..06da6d6 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -26,7 +26,7 @@ OUTPUT_DIR = abspath(join(dirname(__file__), pardir, 'output')) def my_redirect(url): """An overridden redirect to deal with URL_ROOT-ing. See settings.py -for details.""" + for details.""" return redirect(URL_ROOT + url) @@ -54,8 +54,8 @@ def get_user_dir(user): os.mkdir(user_dir) # Make it rwx by others. os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH\ - | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR\ - | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) + | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR\ + | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) return user_dir @@ -123,12 +123,12 @@ def user_register(request): return my_redirect("/exam/start/") else: return my_render_to_response('exam/register.html', - {'form': form}, - context_instance=RequestContext(request)) + {'form': form}, + context_instance=RequestContext(request)) else: form = UserRegisterForm() return my_render_to_response('exam/register.html', - {'form': form}, context_instance=RequestContext(request)) + {'form': form}, context_instance=RequestContext(request)) def quizlist_user(request): @@ -145,7 +145,7 @@ def quizlist_user(request): for paper in user_answerpapers: for quiz in avail_quiz: if paper.question_paper.id == quiz.id and \ - paper.end_time != paper.start_time: + paper.end_time != paper.start_time: avail_quiz.remove(quiz) context = {'quizzes': avail_quiz, 'user': user} @@ -218,10 +218,10 @@ def edit_question(request): question.points = points[j] question.test = test[j] question.options = options[j] - question.type = type[j] - edit_tags = tags[j] question.active = active[j] question.snippet = snippet[j] + question.type = type[j] + edit_tags = tags[j] question.save() for tag in question.tags.all(): question.tags.remove(tag) @@ -264,19 +264,19 @@ def add_question(request, question_id=None): question = Question.objects.get(id=question_id) for tag in question.tags.all(): question.tags.remove(tag) - tags = form['tags'].data.split(', ') + tags = form['tags'].data.split(',') for i in range(0, len(tags)-1): tag = tags[i].strip() question.tags.add(tag) return my_redirect("/exam/manage/questions") else: return my_render_to_response('exam/add_question.html', - {'form': form}, context_instance=RequestContext(request)) + {'form': form}, context_instance=RequestContext(request)) else: if question_id is None: form = QuestionForm() return my_render_to_response('exam/add_question.html', - {'form': form}, context_instance=RequestContext(request)) + {'form': form}, context_instance=RequestContext(request)) else: d = Question.objects.get(id=question_id) form = QuestionForm() @@ -297,13 +297,13 @@ def add_question(request, question_id=None): initial_tags = "" form.initial['tags'] = initial_tags return my_render_to_response('exam/add_question.html', - {'form': form}, - context_instance=RequestContext(request)) + {'form': form}, + context_instance=RequestContext(request)) def add_quiz(request, quiz_id=None): """To add a new quiz in the database. - Create a new question and store it.""" + Create a new quiz and store it.""" user = request.user if not user.is_authenticated() or not is_moderator(user): @@ -337,14 +337,14 @@ def add_quiz(request, quiz_id=None): return my_redirect("/exam/manage/showquiz") else: return my_render_to_response('exam/add_quiz.html', - {'form': form}, - context_instance=RequestContext(request)) + {'form': form}, + context_instance=RequestContext(request)) else: if quiz_id is None: form = QuizForm() return my_render_to_response('exam/add_quiz.html', - {'form': form}, - context_instance=RequestContext(request)) + {'form': form}, + context_instance=RequestContext(request)) else: d = Quiz.objects.get(id=quiz_id) form = QuizForm() @@ -361,8 +361,8 @@ def add_quiz(request, quiz_id=None): initial_tags = "" form.initial['tags'] = initial_tags return my_render_to_response('exam/add_quiz.html', - {'form': form}, - context_instance=RequestContext(request)) + {'form': form}, + context_instance=RequestContext(request)) def design_questionpaper(request, questionpaper_id=None): @@ -370,7 +370,7 @@ def design_questionpaper(request, questionpaper_id=None): if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') return my_render_to_response('exam/add_questionpaper.html', {}, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def show_all_questionpapers(request, questionpaper_id=None): @@ -380,7 +380,7 @@ def show_all_questionpapers(request, questionpaper_id=None): if request.method == "POST" and request.POST.get('add') == "add": return my_redirect("/exam/manage/designquestionpaper/" + \ - questionpaper_id) + questionpaper_id) if request.method == "POST" and request.POST.get('delete') == "delete": data = request.POST.getlist('papers') @@ -390,19 +390,19 @@ def show_all_questionpapers(request, questionpaper_id=None): question_paper = QuestionPaper.objects.all() context = {'papers': question_paper} return my_render_to_response('exam/showquestionpapers.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) if questionpaper_id is None: qu_papers = QuestionPaper.objects.all() context = {'papers': qu_papers} return my_render_to_response('exam/showquestionpapers.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) else: qu_papers = QuestionPaper.objects.get(id=questionpaper_id) quiz = qu_papers.quiz questions = qu_papers.questions.all() context = {'papers': {'quiz': quiz, 'questions': questions}} return my_render_to_response('exam/editquestionpaper.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def automatic_questionpaper(request, questionpaper_id=None): @@ -417,12 +417,18 @@ def automatic_questionpaper(request, questionpaper_id=None): if request.POST.get('save') == 'save': quiz = Quiz.objects.order_by("-id")[0] quest_paper = QuestionPaper() + questions = request.POST.getlist('questions') + tot_marks = 0 + for quest in questions: + if quest.isdigit(): + q = Question.objects.get(id=quest) + tot_marks += q.points quest_paper.quiz = quiz + quest_paper.total_marks = tot_marks quest_paper.save() - questions = request.POST.getlist('questions') - for i in questions: - if i.isdigit(): - q = Question.objects.get(id=i) + for quest in questions: + if quest.isdigit(): + q = Question.objects.get(id=quest) quest_paper.questions.add(q) return my_redirect('/exam/manage/showquiz') else: @@ -439,25 +445,32 @@ def automatic_questionpaper(request, questionpaper_id=None): of Questions...' tags = Tag.objects.all() context = {'data': {'questions': fetched_questions, - 'tags': tags, - 'msg': msg}} + 'tags': tags, + 'msg': msg}} return my_render_to_response(\ - 'exam/automatic_questionpaper.html', context, - context_instance=RequestContext(request)) + 'exam/automatic_questionpaper.html', context, + context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/automatic_questionpaper.html', - context, context_instance=RequestContext(request)) + context, context_instance=RequestContext(request)) else: if request.method == "POST": if request.POST.get('save') == 'save': quest_paper = QuestionPaper.objects.get(id=questionpaper_id) questions = request.POST.getlist('questions') - for i in questions: - if i.isdigit(): - q = Question.objects.get(id=i) + tot_marks = quest_paper.total_marks + for quest in questions: + if quest.isdigit(): + q = Question.objects.get(id=quest) + tot_marks += q.points + quest_paper.total_marks = tot_marks + quest_paper.save() + for quest in questions: + if quest.isdigit(): + q = Question.objects.get(id=quest) quest_paper.questions.add(q) return my_redirect('/exam/manage/showquiz') else: @@ -476,14 +489,14 @@ def automatic_questionpaper(request, questionpaper_id=None): context = {'data': {'questions': fetched_questions, 'tags': tags, 'msg': msg}} - return my_render_to_response( - 'exam/automatic_questionpaper.html', context, - context_instance=RequestContext(request)) + return my_render_to_response\ + ('exam/automatic_questionpaper.html', context, + context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/automatic_questionpaper.html', - context, context_instance=RequestContext(request)) + context, context_instance=RequestContext(request)) def manual_questionpaper(request, questionpaper_id=None): @@ -495,9 +508,15 @@ def manual_questionpaper(request, questionpaper_id=None): if request.method == "POST": if request.POST.get('save') == 'save': questions = request.POST.getlist('questions') - quiz = Quiz.objects.order_by("-id")[0] quest_paper = QuestionPaper() + quiz = Quiz.objects.order_by("-id")[0] + tot_marks = 0 + for quest in questions: + if quest.isdigit(): + q = Question.objects.get(id=quest) + tot_marks += q.points quest_paper.quiz = quiz + quest_paper.total_marks = tot_marks quest_paper.save() for i in questions: q = Question.objects.get(id=i) @@ -511,25 +530,31 @@ def manual_questionpaper(request, questionpaper_id=None): msg = 'No matching Question found...' tags = Tag.objects.all() context = {'data': {'questions': fetched_questions,\ - 'tags': tags, 'msg': msg}} + 'tags': tags, 'msg': msg}} return my_render_to_response('exam/manual_questionpaper.html', - context, - context_instance=RequestContext(request)) + context, + context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/manual_questionpaper.html', - context, context_instance=RequestContext(request)) + context, context_instance=RequestContext(request)) else: if request.method == "POST": if request.POST.get('save') == 'save': quest_paper = QuestionPaper.objects.get(id=questionpaper_id) questions = request.POST.getlist('questions') - for i in questions: - q = Question.objects.get(id=i) - quest_paper.questions.add(q) - return my_redirect('/exam/manage/showquiz') + tot_marks = quest_paper.total_marks + for quest in questions: + q = Question.objects.get(id=quest) + tot_marks += q.points + quest_paper.total_marks = tot_marks + quest_paper.save() + for i in questions: + q = Question.objects.get(id=i) + quest_paper.questions.add(q) + return my_redirect('/exam/manage/showquiz') else: fetched_questions = fetch_questions(request) n = len(fetched_questions) @@ -538,15 +563,16 @@ def manual_questionpaper(request, questionpaper_id=None): msg = 'No matching Question found...' tags = Tag.objects.all() context = {'data': {'questions': fetched_questions,\ - 'tags': tags, 'msg': msg}} + 'tags': tags, 'msg': msg}} return my_render_to_response('exam/manual_questionpaper.html', - context, - context_instance=RequestContext(request)) + context, + context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/manual_questionpaper.html', - context, context_instance=RequestContext(request)) + context, context_instance=RequestContext(request)) + def prof_manage(request): @@ -554,7 +580,7 @@ def prof_manage(request): rights/permissions and log in.""" user = request.user if user.is_authenticated()\ - and user.groups.filter(name='moderator').count() > 0: + and user.groups.filter(name='moderator').count() > 0: context = {'user': user} return my_render_to_response('manage.html', context) return my_redirect('/exam/login/') @@ -580,7 +606,7 @@ def user_login(request): else: context = {"form": form} return my_render_to_response('exam/login.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) else: form = UserLoginForm() context = {"form": form} @@ -600,7 +626,7 @@ def start(request, questionpaper_id=None): questionpaper = QuestionPaper.objects.get(id=questionpaper_id) except QuestionPaper.DoesNotExist: msg = 'Quiz not found, please contact your '\ - 'instructor/administrator. Please login again thereafter.' + 'instructor/administrator. Please login again thereafter.' return complete(request, reason=msg) try: @@ -618,7 +644,7 @@ def start(request, questionpaper_id=None): raise Http404(msg) new_paper = AnswerPaper(user=user, user_ip=ip, - question_paper=questionpaper, profile=profile) + question_paper=questionpaper, profile=profile) new_paper.start_time = datetime.datetime.now() new_paper.end_time = datetime.datetime.now() # Make user directory. @@ -635,10 +661,10 @@ def start(request, questionpaper_id=None): context = {'user': user, 'paper_id': questionpaper_id} ci = RequestContext(request) return my_render_to_response('exam/intro.html', context, - context_instance=ci) + context_instance=ci) -def question(request, q_id, questionpaper_id): +def question(request, q_id, questionpaper_id,success_msg=None): """Check the credentials of the user and start the exam.""" user = request.user @@ -648,7 +674,7 @@ def question(request, q_id, questionpaper_id): try: q_paper = QuestionPaper.objects.get(id=questionpaper_id) paper = AnswerPaper.objects.get(\ - user=request.user, question_paper=q_paper) + user=request.user, question_paper=q_paper) except AnswerPaper.DoesNotExist: return my_redirect('/exam/start/') if not paper.question_paper.quiz.active: @@ -658,21 +684,30 @@ def question(request, q_id, questionpaper_id): if time_left == 0: return complete(request, reason='Your time is up!') quiz_name = paper.question_paper.quiz.description - context = {'question': q, 'paper': paper, 'user': user, - 'quiz_name': quiz_name, - 'time_left': time_left} + if success_msg is None: + context = {'question': q, 'paper': paper, 'user': user, + 'quiz_name': quiz_name, + 'time_left': time_left,} + + else: + context = {'question': q, 'paper': paper, 'user': user, + 'quiz_name': quiz_name, + 'time_left': time_left, + 'success_msg':success_msg} + ci = RequestContext(request) return my_render_to_response('exam/question.html', context, - context_instance=ci) + context_instance=ci) -def show_question(request, q_id, questionpaper_id): +def show_question(request, q_id, questionpaper_id,success_msg=None, + answerpaper_id=None): """Show a question if possible.""" if len(q_id) == 0: msg = 'Congratulations! You have successfully completed the quiz.' - return complete(request, msg) + return complete(request, msg,answerpaper_id) else: - return question(request, q_id, questionpaper_id) + return question(request, q_id, questionpaper_id,success_msg) def check(request, q_id, questionpaper_id=None): @@ -695,15 +730,16 @@ def check(request, q_id, questionpaper_id=None): # Add the answer submitted, regardless of it being correct or not. new_answer = Answer(question=question, answer=user_answer, correct=False) - + new_answer.save() + paper.answers.add(new_answer) else: - # Add the answer submitted with the Snippet code (correct or incorrect) + """Add the answer submitted with the Snippet code, + regardless of it being correct or not.""" answer_check = snippet_code + "\n" + user_answer new_answer = Answer(question=question, answer=answer_check, correct=False) - - new_answer.save() - paper.answers.add(new_answer) + new_answer.save() + paper.answers.add(new_answer) # If we were not skipped, we were asked to check. For any non-mcq # questions, we obtain the results via XML-RPC with the code executed @@ -744,25 +780,40 @@ def check(request, q_id, questionpaper_id=None): context_instance=ci) else: next_q = paper.completed_question(question.id) - return show_question(request, next_q, questionpaper_id) + success_msg = True + return show_question(request, next_q, questionpaper_id,success_msg, + paper.id) def quit(request, answerpaper_id=None): """Show the quit page when the user logs out.""" context = {'id': answerpaper_id} return my_render_to_response('exam/quit.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def complete(request, reason=None, answerpaper_id=None): """Show a page to inform user that the quiz has been compeleted.""" - + user = request.user - if answerpaper_id is None: logout(request) context = {'message': "You are successfully Logged out."} return my_render_to_response('exam/complete.html', context) + else: + paper = AnswerPaper.objects.get(id=answerpaper_id) + obt_marks = paper.get_total_marks() + tot_marks = paper.question_paper.total_marks + print tot_marks + if obt_marks == paper.question_paper.total_marks: + context = {'message': "Hurray ! You did an excellent job.\ + you answered all the questions correctly.\ + You have been logged out successfully,\ + Thank You !"} + else: + context = {'message': reason} + logout(request) + return my_render_to_response('exam/complete.html',context) no = False message = reason or 'The quiz has been completed. Thank you.' if user.groups.filter(name='moderator').count() > 0: @@ -792,7 +843,7 @@ def monitor(request, quiz_id=None): 'quiz': None, 'quizzes': q_paper} return my_render_to_response('exam/monitor.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) # quiz_id is not None. try: quiz = QuestionPaper.objects.get(id=quiz_id) @@ -801,7 +852,7 @@ def monitor(request, quiz_id=None): quiz = None else: papers = AnswerPaper.objects.all().annotate( - total=Sum('answers__marks')).order_by('-total') + total=Sum('answers__marks')).order_by('-total') context = {'papers': papers, 'quiz': quiz, 'quizzes': None} return my_render_to_response('exam/monitor.html', context, @@ -837,7 +888,7 @@ def show_all_users(request): questionpaper = AnswerPaper.objects.all() context = {'question': questionpaper} return my_render_to_response('exam/showusers.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def show_all_quiz(request): @@ -854,19 +905,19 @@ def show_all_quiz(request): if data is None: quizzes = Quiz.objects.all() context = {'papers': [], - 'quiz': None, - 'quizzes': quizzes} + 'quiz': None, + 'quizzes': quizzes} return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) else: for i in data: quiz = Quiz.objects.get(id=i).delete() quizzes = Quiz.objects.all() context = {'papers': [], - 'quiz': None, - 'quizzes': quizzes} + 'quiz': None, + 'quizzes': quizzes} return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) elif request.method == 'POST' and request.POST.get('edit') == 'edit': data = request.POST.getlist('quiz') @@ -888,15 +939,15 @@ def show_all_quiz(request): form.initial['tags'] = initial_tags forms.append(form) return my_render_to_response('exam/edit_quiz.html', - {'forms': forms, 'data': data}, - context_instance=RequestContext(request)) + {'forms': forms, 'data': data}, + context_instance=RequestContext(request)) else: quizzes = Quiz.objects.all() context = {'papers': [], 'quiz': None, 'quizzes': quizzes} return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def show_all_questions(request): @@ -911,19 +962,19 @@ def show_all_questions(request): if data is None: questions = Question.objects.all() context = {'papers': [], - 'question': None, - 'questions': questions} + 'question': None, + 'questions': questions} return my_render_to_response('exam/showquestions.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) else: for i in data: question = Question.objects.get(id=i).delete() questions = Question.objects.all() context = {'papers': [], - 'question': None, - 'questions': questions} + 'question': None, + 'questions': questions} return my_render_to_response('exam/showquestions.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) elif request.method == 'POST' and request.POST.get('edit') == 'edit': data = request.POST.getlist('question') @@ -948,15 +999,15 @@ def show_all_questions(request): form.initial['tags'] = initial_tags forms.append(form) return my_render_to_response('exam/edit_question.html', - {'forms': forms, 'data': data}, - context_instance=RequestContext(request)) + {'forms': forms, 'data': data}, + context_instance=RequestContext(request)) else: questions = Question.objects.all() context = {'papers': [], - 'question': None, - 'questions': questions} + 'question': None, + 'questions': questions} return my_render_to_response('exam/showquestions.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def user_data(request, username): @@ -991,13 +1042,13 @@ def grade_user(request, username): last_ans.marks = marks last_ans.save() paper.comments = request.POST.get(\ - 'comments_%d' % paper.question_paper.id) + 'comments_%d' % paper.question_paper.id) paper.save() context = {'data': data} return my_render_to_response('exam/user_data.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) else: context = {'data': data} return my_render_to_response('exam/grade_user.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) -- cgit