diff options
author | mahesh | 2017-08-17 18:52:55 +0530 |
---|---|---|
committer | mahesh | 2017-08-17 18:52:55 +0530 |
commit | 98386cf63e6f574b38477564b96a5bcab25f2f8f (patch) | |
tree | 7123b5e9e0c912ece9ad8a151c8dbaf318aeecfc /yaksh/models.py | |
parent | 66fc59e724a2a92a8f0b372e64514f42695e66bf (diff) | |
download | online_test-98386cf63e6f574b38477564b96a5bcab25f2f8f.tar.gz online_test-98386cf63e6f574b38477564b96a5bcab25f2f8f.tar.bz2 online_test-98386cf63e6f574b38477564b96a5bcab25f2f8f.zip |
Adds yaml file containing all types of questions
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 7169d37..dfffb53 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -407,25 +407,28 @@ class Question(models.Model): files_list=None): try: questions = ruamel.yaml.safe_load_all(questions_list) + msg = "Questions Uploaded Successfully" for question in questions: question['user'] = user file_names = question.pop('files') test_cases = question.pop('testcase') que, result = Question.objects.get_or_create(**question) - if file_names!="[]": + 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() - msg = "Questions Uploaded Successfully" - except ruamel.yaml.scanner.ScannerError as exc_msg: + try: + 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() + except: + msg = "File not correct." + except Exception as exc_msg: msg = "Error Parsing Yaml: {0}".format(exc_msg) return msg |