summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-03-22 16:56:29 +0530
committerGitHub2017-03-22 16:56:29 +0530
commit99addf818d4b7c5c2d4ccecac7d50b0a5ea89a72 (patch)
tree644c7ff9a21c8f7b14519fe84492341a58099c4c /yaksh/views.py
parent49a4cbac480f8a9e3fafcd50e6ce2fa41a5d8699 (diff)
parent99b0bd05370e92ee3663354e5ca9122b75cfb2a7 (diff)
downloadonline_test-99addf818d4b7c5c2d4ccecac7d50b0a5ea89a72.tar.gz
online_test-99addf818d4b7c5c2d4ccecac7d50b0a5ea89a72.tar.bz2
online_test-99addf818d4b7c5c2d4ccecac7d50b0a5ea89a72.zip
Merge pull request #215 from maheshgudi/fill_in_the_blanks
Fill in the blanks
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 83749c1..bdb6f49 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
@@ -24,8 +25,9 @@ import six
# Local imports.
from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course
from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase, FileUpload,\
- has_profile, StandardTestCase, McqTestCase, StdIOBasedTestCase, HookTestCase
-
+ has_profile, StandardTestCase, McqTestCase,\
+ StdIOBasedTestCase, HookTestCase, IntegerTestCase,\
+ FloatTestCase, StringTestCase
from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\
QuestionForm, RandomQuestionForm,\
QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm,\
@@ -465,6 +467,24 @@ 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, notification=msg
+ )
+ elif current_question.type == 'float':
+ try:
+ user_answer = float(request.POST.get('answer'))
+ except ValueError:
+ msg = "Please enter a Float Value"
+ return show_question(request, current_question,
+ paper, notification=msg)
+ elif current_question.type == 'string':
+ user_answer = str(request.POST.get('answer'))
+
elif current_question.type == 'mcc':
user_answer = request.POST.getlist('answer')
elif current_question.type == 'upload':
@@ -502,9 +522,11 @@ 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.
json_data = current_question.consolidate_answer_data(user_answer, user) \
- if current_question.type == 'code' or \
- current_question.type == 'upload' else None
- result = paper.validate_answer(user_answer, current_question, json_data)
+ if current_question.type == 'code' or \
+ current_question.type == 'upload' else None
+ result = paper.validate_answer(user_answer, current_question,
+ json_data
+ )
if result.get('success'):
new_answer.marks = (current_question.points * result['weight'] /
current_question.get_maximum_test_case_weight()) \