diff options
author | mahesh | 2018-01-15 17:40:06 +0530 |
---|---|---|
committer | maheshgudi | 2018-03-16 15:15:50 +0530 |
commit | 6aeda97b5f37fc7ce50b7fd1f1e0465c42ba0969 (patch) | |
tree | 5793e573cbec6001eb516c91bff73c0e0d9bd72d | |
parent | 06abd01fd28eb10aafd18dd60b790549e0233edc (diff) | |
download | online_test-6aeda97b5f37fc7ce50b7fd1f1e0465c42ba0969.tar.gz online_test-6aeda97b5f37fc7ce50b7fd1f1e0465c42ba0969.tar.bz2 online_test-6aeda97b5f37fc7ce50b7fd1f1e0465c42ba0969.zip |
Add shuffle testcases option to questions
-rw-r--r-- | yaksh/models.py | 51 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_question.html | 1 | ||||
-rw-r--r-- | yaksh/views.py | 2 |
3 files changed, 49 insertions, 5 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() diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index ed69657..b02487c 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -29,6 +29,7 @@ <tr><td>Snippet: <td>{{ qform.snippet }} <tr><td>Minimum Time(in minutes):<td> {{ qform.min_time }} <tr><td>Partial Grading: <td>{{ qform.partial_grading }} + <tr><td>Shuffle Testcases: <td> {{ qform.shuffle_testcases }} <tr><td>Grade Assignment Upload:<td> {{ qform.grade_assignment_upload }} <tr><td> File: <td> {{ fileform.file_field }}{{ fileform.file_field.errors }} {% if uploaded_files %}<br><b>Uploaded files:</b><br>Check on delete to delete files, diff --git a/yaksh/views.py b/yaksh/views.py index 011b417..17cfb13 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -616,7 +616,7 @@ def show_question(request, question, paper, error_message=None, notification=Non if question.type == "code" else 'You have already attempted this question' ) - test_cases = question.get_test_cases() + test_cases = question.get_ordered_test_cases(paper) files = FileUpload.objects.filter(question_id=question.id, hide=False) course = Course.objects.get(id=course_id) module = course.learning_module.get(id=module_id) |