diff options
author | ankitjavalkar | 2016-04-29 11:23:07 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-05 19:21:34 +0530 |
commit | 34fb6b71ce5fcbd9a5537b305504cadaeb86d9a3 (patch) | |
tree | 769c50fc9825ee73eeb7d844db3676a06f2e4e67 /yaksh | |
parent | 5967e0e1cce19d356ba622719b332f776127b277 (diff) | |
download | online_test-34fb6b71ce5fcbd9a5537b305504cadaeb86d9a3.tar.gz online_test-34fb6b71ce5fcbd9a5537b305504cadaeb86d9a3.tar.bz2 online_test-34fb6b71ce5fcbd9a5537b305504cadaeb86d9a3.zip |
- Modify question - answer validation in views
- Modify show_question to include test_cases in template context
- Modify question display template
- Minor changes in forms and urls for proper rebasing
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 12 | ||||
-rw-r--r-- | yaksh/settings.py | 14 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 18 | ||||
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 44 |
5 files changed, 65 insertions, 25 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index d15fdf2..fa4121d 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -250,6 +250,7 @@ class Question(models.Model): return json.dumps(question_data) +<<<<<<< HEAD def dump_into_json(self, question_ids, user): questions = Question.objects.filter(id__in = question_ids, user_id = user.id) questions_dict = [] @@ -270,15 +271,18 @@ class Question(models.Model): question['user'] = user Question.objects.get_or_create(**question) - def get_test_cases(self): + def get_test_cases(self, **kwargs): test_case_ctype = ContentType.objects.get(app_label="yaksh", model=self.test_case_type) - test_cases = test_case_ctype.get_all_objects_for_this_type(question=self) + test_cases = test_case_ctype.get_all_objects_for_this_type(question=self, **kwargs) return test_cases - def get_test_case(self, test_case_id): + # def get_test_case(self, test_case_id): + # test_case_ctype = ContentType.objects.get(app_label="yaksh", model=self.test_case_type) + # test_case = test_case_ctype.get_object_for_this_type(question=self, id=test_case_id) + def get_test_case(self, **kwargs): test_case_ctype = ContentType.objects.get(app_label="yaksh", model=self.test_case_type) - test_case = test_case_ctype.get_object_for_this_type(question=self, id=test_case_id) + test_case = test_case_ctype.get_object_for_this_type(question=self, **kwargs) return test_case diff --git a/yaksh/settings.py b/yaksh/settings.py index aaf6226..f8baa2c 100644 --- a/yaksh/settings.py +++ b/yaksh/settings.py @@ -20,12 +20,12 @@ SERVER_TIMEOUT = 2 URL_ROOT = '' code_evaluators = { - "python": {"standardtestcase": "yaksh.python_assertion_evaluator.PythonAssertionEvaluator", - "stdoutbasedtestcase": "yaksh.python_stdout_evaluator.PythonStdoutEvaluator" + "python": {"standardtestcase": "python_assertion_evaluator.PythonAssertionEvaluator", + "stdoutbasedtestcase": "python_stdout_evaluator.PythonStdoutEvaluator" }, - "c": {"standardtestcase": "yaksh.cpp_code_evaluator.CppCodeEvaluator"}, - "cpp": {"standardtestcase": "yaksh.cpp_code_evaluator.CppCodeEvaluator"}, - "java": {"standardtestcase": "yaksh.java_code_evaluator.JavaCodeEvaluator"}, - "bash": {"standardtestcase": "yaksh.bash_code_evaluator.BashCodeEvaluator"}, - "scilab": {"standardtestcase": "yaksh.scilab_code_evaluator.ScilabCodeEvaluator"}, + "c": {"standardtestcase": "cpp_code_evaluator.CppCodeEvaluator"}, + "cpp": {"standardtestcase": "cpp_code_evaluator.CppCodeEvaluator"}, + "java": {"standardtestcase": "java_code_evaluator.JavaCodeEvaluator"}, + "bash": {"standardtestcase": "bash_code_evaluator.BashCodeEvaluator"}, + "scilab": {"standardtestcase": "scilab_code_evaluator.ScilabCodeEvaluator"}, } diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index e542fe9..8a67818 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -165,8 +165,14 @@ function call_skip(url) <input type=hidden name="question_id" id="question_id" value={{ question.id }}></input> {% if question.type == "mcq" %} - {% for option in question.options.strip.splitlines %} - <input name="answer" type="radio" value="{{option}}" />{{option}} <br/> + {% for test_case in test_cases %} + <input name="answer" type="radio" value="{{ test_case.options }}" />{{ test_case.options }} <br/> + {% endfor %} + {% endif %} + {% if question.type == "mcc" %} + {% for test_case in test_cases %} + <input name="answer" type="checkbox" value="{{ test_case.options }}"> {{ test_case.options }} + <br> {% endfor %} {% endif %} {% if question.type == "upload" %} @@ -174,12 +180,6 @@ function call_skip(url) <input type=file id="assignment" name="assignment"> <hr> {% endif %} - {% if question.type == "mcc" %} - {% for option in question.options.strip.splitlines %} - <input name="answer" type="checkbox" value="{{ option }}"> {{ option }} - <br> - {% endfor %} - {% endif %} {% if question.type == "code" %} <h3>Program:</h3> <textarea rows="1" class="bash" readonly="yes" name="snippet" id="snippet" wrap="off" >{% if last_attempt %}{{ question.snippet }}{% else %}{% if question.type == "bash" %} #!/bin/bash {{ question.snippet }}{% else %}{{ question.snippet }}{% endif %}{% endif %}</textarea> @@ -204,7 +204,7 @@ function call_skip(url) {% endif %} </form> </div> - + <!-- Modal --> <div class="modal fade " id="upload_alert" > <div class="modal-dialog"> diff --git a/yaksh/urls.py b/yaksh/urls.py index 85d7fd1..6a33888 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -41,7 +41,7 @@ urlpatterns += [ url(r'^self_enroll/(?P<course_id>\d+)/$', views.self_enroll), url(r'^manage/$', views.prof_manage), url(r'^manage/addquestion/$', views.add_question), - url(r'^manage/addquestion/(?P<question_id>\d+)/$', views.add_question), + url(r'^manage/addquestion/(?P<question_id>\d+)/$', views.edit_question), url(r'^manage/addquiz/$', views.add_quiz), url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', views.edit_quiz), url(r'^manage/gradeuser/$', views.grade_user), diff --git a/yaksh/views.py b/yaksh/views.py index e478cfe..9492166 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -565,7 +565,9 @@ def show_question(request, question, paper, error_message=None): if paper.time_left() <= 0: reason='Your time is up!' return complete(request, reason, paper.attempt_number, paper.question_paper.id) - context = {'question': question, 'paper': paper, 'error_message': error_message} + test_cases = question.get_test_cases() + context = {'question': question, 'paper': paper, 'error_message': error_message, + 'test_cases': test_cases} answers = paper.get_previous_answers(question) if answers: context['last_attempt'] = answers[0] @@ -666,6 +668,36 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): return show_question(request, question, paper) +# def validate_answer(user, user_answer, question, json_data=None): +# """ +# Checks whether the answer submitted by the user is right or wrong. +# If right then returns correct = True, success and +# message = Correct answer. +# success is True for MCQ's and multiple correct choices because +# only one attempt are allowed for them. +# For code questions success is True only if the answer is correct. +# """ + +# result = {'success': True, 'error': 'Incorrect answer'} +# correct = False + +# if user_answer is not None: +# if question.type == 'mcq': +# if user_answer.strip() == question.test.strip(): +# correct = True +# elif question.type == 'mcc': +# answers = set(question.test.splitlines()) +# if set(user_answer) == answers: +# correct = True +# elif question.type == 'code': +# user_dir = get_user_dir(user) +# json_result = code_server.run_code(question.language, question.test_case_type, json_data, user_dir) +# result = json.loads(json_result) +# if result.get('success'): +# correct = True + +# return correct, result + def validate_answer(user, user_answer, question, json_data=None): """ Checks whether the answer submitted by the user is right or wrong. @@ -681,11 +713,15 @@ def validate_answer(user, user_answer, question, json_data=None): if user_answer is not None: if question.type == 'mcq': - if user_answer.strip() == question.test.strip(): + expected_answer = question.get_test_case(correct=True).options + if user_answer.strip() == expected_answer.strip(): correct = True elif question.type == 'mcc': - answers = set(question.test.splitlines()) - if set(user_answer) == answers: + expected_answers = [] + for opt in question.get_test_cases(correct=True): + expected_answers.append(opt.options) + # answers = set(question.test.splitlines()) + if set(user_answer) == set(expected_answers): correct = True elif question.type == 'code': user_dir = get_user_dir(user) |