diff options
author | Prabhu Ramachandran | 2016-07-05 10:03:59 -0400 |
---|---|---|
committer | GitHub | 2016-07-05 10:03:59 -0400 |
commit | d67c2f3933db20d9d68c826e3a2964947163d97a (patch) | |
tree | 469148f976c77b45e662f0c9e00f6af56a0e45ac /yaksh/models.py | |
parent | 0245ad5d20820fdf0cdcdec7f5d4e153289e7e3d (diff) | |
parent | e3296e0354733f6db1b668769849db00322b2fc4 (diff) | |
download | online_test-d67c2f3933db20d9d68c826e3a2964947163d97a.tar.gz online_test-d67c2f3933db20d9d68c826e3a2964947163d97a.tar.bz2 online_test-d67c2f3933db20d9d68c826e3a2964947163d97a.zip |
Merge pull request #108 from adityacp/fix_questions_upload
Fix load and dump questions
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 2c1554a..7035d1e 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -184,7 +184,7 @@ class Question(models.Model): # The type of evaluator test_case_type = models.CharField(max_length=24, choices=test_case_types) - + # Is this question active or not. If it is inactive it will not be used # when creating a QuestionPaper. active = models.BooleanField(default=True) @@ -214,17 +214,19 @@ class Question(models.Model): return json.dumps(question_data) def dump_into_json(self, question_ids, user): - questions = Question.objects.filter(id__in = question_ids, user_id = user.id) + questions = Question.objects.filter(id__in=question_ids, user_id=user.id) questions_dict = [] for question in questions: - q_dict = {'summary': question.summary, - 'description': question.description, - 'points': question.points, - 'language': question.language, - 'type': question.type, - 'active': question.active, - 'test_case_type': question.test_case_type, - 'snippet': question.snippet} + test_case = question.get_test_cases() + q_dict = {'summary': question.summary, + 'description': question.description, + 'points': question.points, + 'language': question.language, + 'type': question.type, + 'active': question.active, + 'test_case_type': question.test_case_type, + 'snippet': question.snippet, + 'testcase': [case.get_field_value() for case in test_case]} questions_dict.append(q_dict) return json.dumps(questions_dict, indent=2) @@ -233,7 +235,11 @@ class Question(models.Model): questions = json.loads(questions_list) for question in questions: question['user'] = user - Question.objects.get_or_create(**question) + test_cases = question.pop('testcase') + que, result = Question.objects.get_or_create(**question) + model_class = get_model_class(que.test_case_type) + for test_case in test_cases: + model_class.objects.get_or_create(question=que, **test_case) def get_test_cases(self, **kwargs): test_case_ctype = ContentType.objects.get(app_label="yaksh", |