diff options
author | adityacp | 2017-03-16 16:43:12 +0530 |
---|---|---|
committer | adityacp | 2017-03-16 16:43:12 +0530 |
commit | b37244f2c6573b0f16b9dcea614400ee1ae24cf8 (patch) | |
tree | e5ae120f2c47d78e53513db25e01d028954d9f5f /yaksh/models.py | |
parent | 508a576ccfb63169c24056ded25f742bdcd186f2 (diff) | |
download | online_test-b37244f2c6573b0f16b9dcea614400ee1ae24cf8.tar.gz online_test-b37244f2c6573b0f16b9dcea614400ee1ae24cf8.tar.bz2 online_test-b37244f2c6573b0f16b9dcea614400ee1ae24cf8.zip |
Changes in models views and urls
- Handle Json parsing error
- Remove Sample file download from views and urls
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 0a84d4e..dc015d5 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -318,17 +318,19 @@ class Question(models.Model): file_names = question.pop('files') test_cases = question.pop('testcase') que, result = Question.objects.get_or_create(**question) - if file_names: - que._add_files_to_db(file_names, file_path) - for test_case in test_cases: - test_case_type = test_case.pop('test_case_type') - model_class = get_model_class(test_case_type) - new_test_case, obj_create_status = \ - model_class.objects.get_or_create( - question=que, **test_case - ) - new_test_case.type = test_case_type - new_test_case.save() + if not result: + if file_names: + que._add_files_to_db(file_names, file_path) + for test_case in test_cases: + test_case_type = test_case.pop('test_case_type') + model_class = get_model_class(test_case_type) + new_test_case, obj_create_status = \ + model_class.objects.get_or_create( + question=que, **test_case + ) + new_test_case.type = test_case_type + new_test_case.save() + if files_list: delete_files(files_list, file_path) @@ -401,7 +403,11 @@ class Question(models.Model): if os.path.exists(json_file): with open(json_file, 'r') as q_file: questions_list = q_file.read() - self.load_questions(questions_list, user, file_path, files) + try: + self.load_questions(questions_list, user, file_path, files) + except ValueError: + return "Syntax Error in Json. Please check your json file." + return "Questions Uploaded Successfully" else: return "Please upload zip file with questions_dump.json in it." |