summaryrefslogtreecommitdiff
path: root/testapp/exam/views.py
diff options
context:
space:
mode:
authorankitjavalkar2015-03-18 12:16:20 +0530
committerankitjavalkar2015-04-26 19:46:00 +0530
commit28ba37e907553aeac3841e221853683b9171f0db (patch)
tree9926315f93ac82fb21ae1f98450cfa031da8f996 /testapp/exam/views.py
parenta88e59fa419d7ab31aa430e7424ff0a25169713f (diff)
downloadonline_test-28ba37e907553aeac3841e221853683b9171f0db.tar.gz
online_test-28ba37e907553aeac3841e221853683b9171f0db.tar.bz2
online_test-28ba37e907553aeac3841e221853683b9171f0db.zip
Changes to Question model, Views, Add-Question UI
- ref_code_path is now part of Question model - MCQ/MCC answers checked using solution field in question model - Formset should reload even after errors - add_question page chould display solution field only in MCQ/MCC
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r--testapp/exam/views.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 8aef5ab..840f30a 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -323,7 +323,7 @@ def add_question(request, question_id=None):
def add_or_delete_test_form(post_request, instance):
request_copy = post_request.copy()
if 'add_test' in post_request:
- request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) + 1
+ request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) + 1
elif 'delete_test' in post_request:
request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) - 1
test_case_formset = TestCaseFormSet(request_copy, prefix='test', instance=instance)
@@ -402,8 +402,10 @@ def add_question(request, question_id=None):
context_instance=ci)
else:
+ test_case_formset = add_or_delete_test_form(request.POST, form.save(commit=False))
return my_render_to_response('exam/add_question.html',
- {'form': form},
+ {'form': form,
+ 'formset': test_case_formset},
context_instance=ci)
else:
form = QuestionForm()
@@ -951,8 +953,8 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
# questions, we obtain the results via XML-RPC with the code executed
# safely in a separate process (the code_server.py) running as nobody.
if not question.type == 'upload':
- if question.type == 'code':
- info_parameter = question.consolidate_answer_data(test, user_answer)
+ info_parameter = question.consolidate_answer_data(test, user_answer) \
+ if question.type == 'code' else None
correct, result = validate_answer(user, user_answer, question, info_parameter)
if correct:
new_answer.correct = correct
@@ -1013,11 +1015,11 @@ def validate_answer(user, user_answer, question, info_parameter=None):
if user_answer is not None:
if question.type == 'mcq':
- if user_answer.strip() == question.test.strip(): ####add question.answer/question.solution instead of test
+ if user_answer.strip() == question.solution.strip():
correct = True
message = 'Correct answer'
elif question.type == 'mcc':
- answers = set(question.test.splitlines()) ####add question.answer/question.solution instead of test
+ answers = set(question.solution.splitlines())
if set(user_answer) == answers:
correct = True
message = 'Correct answer'