From ddf3e13669f7232acf6019a0f2f33f397a6e6d51 Mon Sep 17 00:00:00 2001 From: maheshgudi Date: Mon, 30 Jan 2017 16:20:18 +0530 Subject: added string based questions. --- yaksh/forms.py | 2 +- yaksh/models.py | 34 ++++++++++++++++++++++++++++++++- yaksh/static/yaksh/css/question.css | 5 +++++ yaksh/templates/yaksh/add_question.html | 1 + yaksh/templates/yaksh/question.html | 11 +++++++++-- yaksh/views.py | 14 ++++++++++---- 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/yaksh/forms.py b/yaksh/forms.py index 4bf4fcf..df590de 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -1,7 +1,7 @@ from django import forms from yaksh.models import get_model_class, Profile, Quiz, Question, TestCase, Course,\ QuestionPaper, StandardTestCase, StdIOBasedTestCase, \ - HookTestCase, IntegerTestCase + HookTestCase, IntegerTestCase, StringTestCase from django.contrib.auth import authenticate from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType diff --git a/yaksh/models.py b/yaksh/models.py index 81b8d7f..6381d4b 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -41,6 +41,7 @@ question_types = ( ("code", "Code"), ("upload", "Assignment Upload"), ("integer", "Answer in Integer"), + ("string", "Answer in String"), ) enrollment_methods = ( @@ -54,6 +55,12 @@ test_case_types = ( ("mcqtestcase", "MCQ Testcase"), ("hooktestcase", "Hook Testcase"), ("integertestcase", "Integer Testcase"), + ("stringtestcase", "String Testcase"), + ) + +string_check_type = ( + ("lower", "Lower case Checking"), + ("exact", "Exact case String Checking"), ) attempts = [(i, i) for i in range(1, 6)] @@ -1135,11 +1142,24 @@ class AnswerPaper(models.Model): if set(user_answer) == set(expected_answers): result['success'] = True result['error'] = ['Correct answer'] + elif question.type == 'integer': expected_answer = question.get_test_case().correct if expected_answer == int(user_answer): result['success'] = True result['error'] = ['Correct answer'] + + elif question.type == 'string': + testcase = question.get_test_case() + if testcase.string_check == "lower": + if testcase.correct.lower() == user_answer.lower(): + result['success'] = True + result['error'] = ['Correct answer'] + else: + if testcase.correct == user_answer: + result['success'] = True + result['error'] = ['Correct answer'] + elif question.type == 'code': user_dir = self.user.profile.get_user_dir() json_result = code_server.run_code( @@ -1289,10 +1309,22 @@ class HookTestCase(TestCase): return u'Hook Testcase | Correct: {0}'.format(self.hook_code) class IntegerTestCase(TestCase): - correct = models.IntegerField(default=False) + correct = models.IntegerField(default=None) def get_field_value(self): return {"test_case_type": "integertestcase", "correct": self.correct} def __str__(self): return u'Integer Testcase | Correct: {0}'.format(self.correct) + + +class StringTestCase(TestCase): + correct = models.TextField(default=None) + string_check = models.CharField(max_length=200,choices=string_check_type) + + def get_field_value(self): + return {"test_case_type": "stringtestcase", "correct": self.correct, + "string_check":self.string_check} + + def __str__(self): + return u'String Testcase | Correct: {0}'.format(self.correct) diff --git a/yaksh/static/yaksh/css/question.css b/yaksh/static/yaksh/css/question.css index 9fb2e1a..fdbe5f2 100644 --- a/yaksh/static/yaksh/css/question.css +++ b/yaksh/static/yaksh/css/question.css @@ -36,3 +36,8 @@ .lineObj{ color: grey; } + +#string{ + width: 60em; + height: 10em; +} diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index a1b5e90..de3ce56 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -57,6 +57,7 @@ +