diff options
author | mahesh | 2018-01-15 17:40:06 +0530 |
---|---|---|
committer | maheshgudi | 2018-03-16 15:17:20 +0530 |
commit | 9c5464a6edaaf2aaafc0e42fe88c8734fd952e12 (patch) | |
tree | 5793e573cbec6001eb516c91bff73c0e0d9bd72d /yaksh/models.py | |
parent | 06abd01fd28eb10aafd18dd60b790549e0233edc (diff) | |
download | online_test-9c5464a6edaaf2aaafc0e42fe88c8734fd952e12.tar.gz online_test-9c5464a6edaaf2aaafc0e42fe88c8734fd952e12.tar.bz2 online_test-9c5464a6edaaf2aaafc0e42fe88c8734fd952e12.zip |
Add shuffle testcases option to questions
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index f065190..6ba4589 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -815,8 +815,14 @@ class Question(models.Model): min_time = models.IntegerField("time in minutes", default=0) + #Solution for the question. solution = models.TextField(blank=True) + # Shuffle testcase order. + shuffle_testcases = models.BooleanField("Shuffle testcase for each user", + default=False + ) + def consolidate_answer_data(self, user_answer, user=None): question_data = {} metadata = {} @@ -928,6 +934,17 @@ class Question(models.Model): return test_case + def get_ordered_test_cases(self, answerpaper): + try: + order = TestcaseOrder.objects.get(answer_paper=answerpaper, + question = self + ).testcase_order.split(",") + return [self.get_test_cases(id=int(tc_id))[0]\ + for tc_id in order + ] + except TestcaseOrder.DoesNotExist: + return self.get_test_cases() + def get_maximum_test_case_weight(self, **kwargs): max_weight = 0.0 for test_case in self.get_test_cases(): @@ -1197,7 +1214,17 @@ class QuestionPaper(models.Model): ans_paper.save() questions = self._get_questions_for_answerpaper() ans_paper.questions.add(*questions) - question_ids = [str(que.id) for que in questions] + question_ids = [] + for question in questions: + question_ids.append(str(question.id)) + testcases = question.get_test_cases() + if question.shuffle_testcases: + random.shuffle(testcases) + testcases_ids = ",".join([str(tc.id) for tc in testcases]) + testcases_order = TestcaseOrder.objects.create( + answer_paper=ans_paper, + question=question, + testcase_order=testcases_ids) ans_paper.questions_order = ",".join(question_ids) ans_paper.save() ans_paper.questions_unanswered.add(*questions) @@ -1829,7 +1856,7 @@ class AnswerPaper(models.Model): .format(u.first_name, u.last_name, q.description) -################################################################################ +############################################################################## class AssignmentUploadManager(models.Manager): def get_assignments(self, qp, que_id=None, user_id=None): @@ -1851,7 +1878,7 @@ class AssignmentUploadManager(models.Manager): return assignment_files, file_name -################################################################################ +############################################################################## class AssignmentUpload(models.Model): user = models.ForeignKey(User) assignmentQuestion = models.ForeignKey(Question) @@ -1860,7 +1887,7 @@ class AssignmentUpload(models.Model): objects = AssignmentUploadManager() -############################################################################### +############################################################################## class TestCase(models.Model): question = models.ForeignKey(Question, blank=True, null=True) type = models.CharField(max_length=24, choices=test_case_types, null=True) @@ -1978,3 +2005,19 @@ class FloatTestCase(TestCase): return u'Testcase | Correct: {0} | Error Margin: +or- {1}'.format( self.correct, self.error_margin ) + + +############################################################################## +class TestcaseOrder(models.Model): + """Testcase order contains a set of ordered test cases for a given question + for each user. + """ + + # Answerpaper of the user. + answer_paper= models.ForeignKey(AnswerPaper,related_name="answer_paper") + + # Question in an answerpaper. + question = models.ForeignKey(Question) + + #Order of the test case for a question. + testcase_order = models.TextField() |