summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py47
1 files changed, 41 insertions, 6 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index d9eea57..826c0e8 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -54,6 +54,8 @@ question_types = (
("integer", "Answer in Integer"),
("string", "Answer in String"),
("float", "Answer in Float"),
+ ("arrange", "Arrange in Correct Order"),
+
)
enrollment_methods = (
@@ -69,6 +71,7 @@ test_case_types = (
("integertestcase", "Integer Testcase"),
("stringtestcase", "String Testcase"),
("floattestcase", "Float Testcase"),
+ ("arrangetestcase", "Arrange Testcase"),
)
string_check_type = (
@@ -1276,8 +1279,8 @@ class QuestionPaper(models.Model):
question_ids = []
for question in questions:
question_ids.append(str(question.id))
- if self.shuffle_testcases and \
- question.type in ["mcq", "mcc"]:
+ if (question.type == "arrange") or (self.shuffle_testcases
+ and question.type in ["mcq", "mcc"]):
testcases = question.get_test_cases()
random.shuffle(testcases)
testcases_ids = ",".join([str(tc.id) for tc in testcases]
@@ -1849,6 +1852,15 @@ class AnswerPaper(models.Model):
result['success'] = True
result['error'] = ['Correct answer']
+ elif question.type == 'arrange':
+ testcase_ids = sorted(
+ [tc.id for tc in question.get_test_cases()]
+ )
+ if user_answer == testcase_ids:
+ result['success'] = True
+ result['error'] = ['Correct answer']
+
+
elif question.type == 'code' or question.type == "upload":
user_dir = self.user.profile.get_user_dir()
url = '{0}:{1}'.format(SERVER_HOST_NAME, server_port)
@@ -1870,13 +1882,21 @@ class AnswerPaper(models.Model):
user_answer = self.answers.filter(question=question).last()
if not user_answer:
return False, msg + 'Did not answer.'
- if question.type == 'mcc':
+ if question.type in ['mcc', 'arrange']:
try:
- answer = eval(user_answer.answer)
+ answer = literal_eval(user_answer.answer)
if type(answer) is not list:
- return False, msg + 'MCC answer not a list.'
+ return (False,
+ msg + '{0} answer not a list.'.format(
+ question.type
+ )
+ )
except Exception:
- return False, msg + 'MCC answer submission error'
+ return (False,
+ msg + '{0} answer submission error'.format(
+ question.type
+ )
+ )
else:
answer = user_answer.answer
json_data = question.consolidate_answer_data(answer) \
@@ -2069,6 +2089,18 @@ class FloatTestCase(TestCase):
)
+class ArrangeTestCase(TestCase):
+
+ options = models.TextField(default=None)
+
+ def get_field_value(self):
+ return {"test_case_type": "arrangetestcase",
+ "options": self.options}
+
+ def __str__(self):
+ return u'Arrange Testcase | Option: {0}'.format(self.options)
+
+
##############################################################################
class TestCaseOrder(models.Model):
"""Testcase order contains a set of ordered test cases for a given question
@@ -2083,3 +2115,6 @@ class TestCaseOrder(models.Model):
#Order of the test case for a question.
order = models.TextField()
+
+
+##############################################################################