From e44bd4577bf839148c0824a9d3cc84a789f25b95 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 11 Aug 2014 13:00:33 +0530 Subject: redirect to dashboard after exam. After exam is over or time-out the user is redirected to the result page. The user is not logged out. Current time is checked with the quiz end time, so that the user cannot reattempt the quiz. --- testapp/exam/views.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 7c9af6c..aeb93ca 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -22,6 +22,7 @@ from exam.forms import UserRegisterForm, UserLoginForm, QuizForm,\ from exam.xmlrpc_clients import code_server from settings import URL_ROOT + # The directory where user data can be saved. OUTPUT_DIR = abspath(join(dirname(__file__), 'output')) @@ -142,7 +143,6 @@ def quizlist_user(request): pre_requisites = [] context = {} - if 'cannot_attempt' in request.GET: context['cannot_attempt'] = True @@ -155,7 +155,7 @@ def quizlist_user(request): for answer_paper in user_answerpapers: for quiz in avail_quizzes: if answer_paper.question_paper.id == quiz.id and \ - answer_paper.end_time != answer_paper.start_time: + answer_paper.end_time != answer_paper.start_time: avail_quizzes.remove(quiz) quizzes_taken.append(answer_paper) @@ -181,11 +181,11 @@ def intro(request, questionpaper_id): return my_render_to_response('exam/intro.html', context, context_instance=ci) else: - context = {'user': user, 'cannot_attempt':True} + context = {'user': user, 'cannot_attempt': True} return my_redirect("/exam/quizzes/?cannot_attempt=True") except: - context = {'user': user, 'cannot_attempt':True} + context = {'user': user, 'cannot_attempt': True} return my_redirect("/exam/quizzes/?cannot_attempt=True") context = {'user': user, 'paper_id': questionpaper_id} ci = RequestContext(request) @@ -389,7 +389,7 @@ def add_quiz(request, quiz_id=None): form.initial['active'] = d.active form.initial['pass_criteria'] = d.pass_criteria form.initial['language'] = d.language - form.initial['prerequisite'] = d.prerequisite_id + form.initial['prerequisite'] = d.prerequisite_id return my_render_to_response('exam/add_quiz.html', {'form': form}, context_instance=ci) @@ -607,10 +607,11 @@ rights/permissions and log in.""" users_failed = AnswerPaper.objects.filter(question_paper=paper, 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} + context = {'user': user, 'users_per_paper': users_per_paper} return my_render_to_response('manage.html', context) return my_redirect('/exam/login/') + def user_login(request): """Take the credentials of the user and log the user in.""" @@ -691,6 +692,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) + elif paper.end_time < datetime.datetime.now(): + reason = 'You have already attempted the quiz' + return complete(request, reason, questionpaper_id) time_left = paper.time_left() if time_left == 0: return complete(request, reason='Your time is up!') @@ -722,11 +726,11 @@ def check(request, q_id, questionpaper_id=None): """Checks the answers of the user for particular question""" user = request.user - if not user.is_authenticated(): - return my_redirect('/exam/login/') - question = get_object_or_404(Question, pk=q_id) q_paper = QuestionPaper.objects.get(id=questionpaper_id) paper = AnswerPaper.objects.get(user=request.user, question_paper=q_paper) + if not user.is_authenticated() or paper.end_time < datetime.datetime.now(): + return my_redirect('/exam/login/') + question = get_object_or_404(Question, pk=q_id) snippet_code = request.POST.get('snippet') skip = request.POST.get('skip', None) success_msg = False @@ -816,7 +820,7 @@ def validate_answer(user, user_answer, question): success, message = code_server.run_code(user_answer, question.test, user_dir, question.language) if success: - correct = True + correct = True return correct, success, message @@ -842,6 +846,7 @@ def complete(request, reason=None, questionpaper_id=None): paper.update_marks_obtained() paper.update_percent() paper.update_passed() + paper.end_time = datetime.datetime.now() paper.save() obt_marks = paper.marks_obtained tot_marks = paper.question_paper.total_marks @@ -850,12 +855,10 @@ def complete(request, reason=None, questionpaper_id=None): you answered all the questions correctly.\ You have been logged out successfully,\ Thank You !"} - logout(request) return my_render_to_response('exam/complete.html', context) else: message = reason or "You are successfully logged out" context = {'message': message} - logout(request) return my_render_to_response('exam/complete.html', context) no = False message = reason or 'The quiz has been completed. Thank you.' @@ -866,7 +869,7 @@ def complete(request, reason=None, questionpaper_id=None): if not no: # Logout the user and quit with the message given. answer_paper = AnswerPaper.objects.get(id=answerpaper_id) - answer_paper.endtime = datetime.datetime.now() + answer_paper.end_time = datetime.datetime.now() answer_paper.save() return my_redirect('/exam/quizzes/') else: @@ -1118,8 +1121,8 @@ def ajax_questionpaper(request, query): question_list = fixed_question_list + random_question_list questions = list(Question.objects.filter(type=question_type, points=marks_selected)) - questions = [ question for question in questions \ - if not str(question.id) in question_list ] + questions = [question for question in questions \ + if not str(question.id) in question_list] return my_render_to_response('exam/ajax_questions.html', {'questions': questions}) @@ -1147,7 +1150,7 @@ def design_questionpaper(request): question_paper.save() if fixed_questions: fixed_questions_ids = ",".join(fixed_questions) - fixed_questions_ids_list = fixed_questions_ids.split(',') + fixed_questions_ids_list = fixed_questions_ids.split(',') for question_id in fixed_questions_ids_list: question_paper.fixed_questions.add(question_id) if random_questions: -- cgit From 962cee1705509bb595cda51d104ef1ef7cf0b4fd Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 11 Aug 2014 14:44:48 +0530 Subject: fixed minor issues in css. --- testapp/exam/static/exam/css/question_quiz.css | 12 +++++++++--- testapp/exam/static/exam/js/add_quiz.js | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/static/exam/css/question_quiz.css b/testapp/exam/static/exam/css/question_quiz.css index b702bd4..ee249d4 100644 --- a/testapp/exam/static/exam/css/question_quiz.css +++ b/testapp/exam/static/exam/css/question_quiz.css @@ -5,14 +5,20 @@ table th, table td .mini-text { - height : 9px; - width : 30px; + height : 25px; + width : 70px; } .select-type { - width : 80px; + width : 225px; } .tag-text { + height : 30px; width : 290px; } +.date-text +{ + height : 30px; + width : 100px; +} diff --git a/testapp/exam/static/exam/js/add_quiz.js b/testapp/exam/static/exam/js/add_quiz.js index d5688a8..184881c 100644 --- a/testapp/exam/static/exam/js/add_quiz.js +++ b/testapp/exam/static/exam/js/add_quiz.js @@ -1,5 +1,9 @@ function test() { + + document.getElementById('id_duration').setAttribute('class','mini-text'); + document.getElementById('id_pass_criteria').setAttribute('class','mini-text'); + document.getElementById('id_start_date').setAttribute('class','date-text'); if (document.getElementById("id_description").value != "") { document.getElementById("submit").innerHTML = "Save"; -- cgit From 663e9945eddeda6bfe37b5d64c1a08a85d222f3e Mon Sep 17 00:00:00 2001 From: prathamesh Date: Thu, 19 Feb 2015 12:05:47 +0530 Subject: README modified. Added command to install the app. The app is installed from the github repository. --- testapp/README.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'testapp') diff --git a/testapp/README.rst b/testapp/README.rst index 6f49d4b..f4790a3 100644 --- a/testapp/README.rst +++ b/testapp/README.rst @@ -10,7 +10,10 @@ conduct online test and monitor the test. Quick start ------------ -1. Add "testapp.exam", "taggit" and "taggit_autocomplete_modified" apps +1. In yourterminal run the following command:: + $ easy_install git+https://github.com/FOSSEE/online_test.git#egg=django_exam-0.1 + +2. Add "testapp.exam", "taggit" and "taggit_autocomplete_modified" apps to your INSTALLED_APPS setting as follows:: INSTALLED_APPS =( @@ -19,10 +22,10 @@ Quick start 'taggit_autocomplete_modified', ) -2. In project settings, add AUTH_PROFILE_MODULE = 'testapp.exam.Profile' +3. In project settings, add AUTH_PROFILE_MODULE = 'testapp.exam.Profile' You can change the testapp.exam.Profile to your desired app user profile. -3. Include the "testapp.exam" and taggit_autocomplete_modified URL configuration +4. Include the "testapp.exam" and taggit_autocomplete_modified URL configuration in your project urls.py as follows:: url(r'^exam/', include('testapp.exam.urls')), @@ -30,11 +33,11 @@ Quick start ('taggit_autocomplete_modified.urls')) -4. Run 'python manage.py syncdb' to create models for the new installed apps. +5. Run 'python manage.py syncdb' to create models for the new installed apps. -5. Start the development server and visit http://localhost:8000/exam/ +6. Start the development server and visit http://localhost:8000/exam/ -6. In exam app run code_sever command as superuser as follows:: +7. In exam app run code_sever command as superuser as follows:: $ code_server -- cgit From 3f9be69fd9af4a169feb1a49e6d89839073b4da5 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Wed, 4 Mar 2015 17:13:14 +0530 Subject: Corrected a logical issue in the random questions for question paper generation. --- testapp/exam/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'testapp') diff --git a/testapp/exam/views.py b/testapp/exam/views.py index c6e3024..474fa2f 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -1155,7 +1155,8 @@ def design_questionpaper(request): question_paper.fixed_questions.add(question_id) if random_questions: for random_question, num in zip(random_questions, random_number): - question = Question.objects.get(id=random_question[0]) + qid = random_question.split(',')[0] + question = Question.objects.get(id=int(qid)) marks = question.points question_set = QuestionSet(marks=marks, num_questions=num) question_set.save() -- cgit From 89f4db581db2b8260fad4dec3e77ac9b8a93d4a9 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Wed, 25 Mar 2015 12:31:24 +0530 Subject: Made changes to the Readme as per the comments --- testapp/README.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'testapp') diff --git a/testapp/README.rst b/testapp/README.rst index f4790a3..72b666c 100644 --- a/testapp/README.rst +++ b/testapp/README.rst @@ -10,7 +10,7 @@ conduct online test and monitor the test. Quick start ------------ -1. In yourterminal run the following command:: +1. In your terminal run the following command:: $ easy_install git+https://github.com/FOSSEE/online_test.git#egg=django_exam-0.1 2. Add "testapp.exam", "taggit" and "taggit_autocomplete_modified" apps @@ -35,9 +35,10 @@ Quick start 5. Run 'python manage.py syncdb' to create models for the new installed apps. -6. Start the development server and visit http://localhost:8000/exam/ +6. Run 'python manage.py runserver' to start the development server + and visit http://localhost:8000/exam/ -7. In exam app run code_sever command as superuser as follows:: +7. Run code_server command as superuser as follows:: $ code_server -- cgit From 1fe37566ab72b2d7e53d36c36948e50086e7059a Mon Sep 17 00:00:00 2001 From: prathamesh Date: Fri, 27 Mar 2015 12:13:19 +0530 Subject: Added note about virtual python environment in the README --- testapp/README.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'testapp') diff --git a/testapp/README.rst b/testapp/README.rst index 72b666c..e6f8380 100644 --- a/testapp/README.rst +++ b/testapp/README.rst @@ -40,6 +40,9 @@ Quick start 7. Run code_server command as superuser as follows:: - $ code_server + $ sudo code_server - Note: You must have a sudo access to run the above command. + Note: If you are using virtual python environment, then activate the environment + using sudo. Then simply run the code_server command as follows:: + + $ code_server -- cgit