summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authormaheshgudi2017-01-30 16:20:18 +0530
committermaheshgudi2017-03-02 20:38:41 +0530
commitddf3e13669f7232acf6019a0f2f33f397a6e6d51 (patch)
tree361639cc9cdd015cc0f80644885d8bc96ac74daf /yaksh/views.py
parent4ef5f9377c27a3e88ae3a1a4e2a446984fc14b70 (diff)
downloadonline_test-ddf3e13669f7232acf6019a0f2f33f397a6e6d51.tar.gz
online_test-ddf3e13669f7232acf6019a0f2f33f397a6e6d51.tar.bz2
online_test-ddf3e13669f7232acf6019a0f2f33f397a6e6d51.zip
added string based questions.
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 996a3ce..6a19744 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -16,6 +16,7 @@ from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from django.forms.models import inlineformset_factory
from django.utils import timezone
+from django.core.exceptions import MultipleObjectsReturned
import pytz
from taggit.models import Tag
from itertools import chain
@@ -469,13 +470,14 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
# Add the answer submitted, regardless of it being correct or not.
if current_question.type == 'mcq':
user_answer = request.POST.get('answer')
-
elif current_question.type == 'integer':
try:
user_answer = int(request.POST.get('answer'))
except ValueError:
msg = ["Please enter an Integer Value"]
return show_question(request, current_question, paper, msg)
+ elif current_question.type == 'string':
+ user_answer = str(request.POST.get('answer'))
elif current_question.type == 'mcc':
user_answer = request.POST.getlist('answer')
@@ -504,9 +506,13 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
# 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
# safely in a separate process (the code_server.py) running as nobody.
- json_data = current_question.consolidate_answer_data(user_answer) \
- if current_question.type == 'code' else None
- result = paper.validate_answer(user_answer, current_question, json_data)
+ try:
+ json_data = current_question.consolidate_answer_data(user_answer) \
+ if current_question.type == 'code' else None
+ result = paper.validate_answer(user_answer, current_question, json_data)
+ except MultipleObjectsReturned:
+ msg = ["Multiple objects returned. Contact admin."]
+ return show_question(request, current_question, paper, msg)
if result.get('success'):
new_answer.marks = (current_question.points * result['weight'] /
current_question.get_maximum_test_case_weight()) \