diff options
author | adityacp | 2017-03-17 22:08:45 +0530 |
---|---|---|
committer | adityacp | 2017-03-17 22:08:45 +0530 |
commit | f29b18cdb0062e124a8f534bebde112e31d308c5 (patch) | |
tree | 85ab68365da6f05263c614a230c2ec0fb17c5c8b /yaksh/models.py | |
parent | b4b33cc37244ed59765c705c6d882c00ddc88c62 (diff) | |
parent | 23ecd8fa33e7fa2e953aa9715ae45a2869a044a0 (diff) | |
download | online_test-f29b18cdb0062e124a8f534bebde112e31d308c5.tar.gz online_test-f29b18cdb0062e124a8f534bebde112e31d308c5.tar.bz2 online_test-f29b18cdb0062e124a8f534bebde112e31d308c5.zip |
Merge https://github.com/fossee/online_test into assignment_upload_check
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index f6efeba..03a67e6 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -15,6 +15,8 @@ except ImportError: from io import BytesIO as string_io import pytz import os +import sys +import traceback import stat from os.path import join, exists import shutil @@ -322,7 +324,11 @@ class Question(models.Model): def load_questions(self, questions_list, user, file_path=None, files_list=None): - questions = json.loads(questions_list) + try: + questions = json.loads(questions_list) + except ValueError as exc_msg: + msg = "Error Parsing Json: {0}".format(exc_msg) + return msg for question in questions: question['user'] = user file_names = question.pop('files') @@ -339,8 +345,7 @@ class Question(models.Model): ) new_test_case.type = test_case_type new_test_case.save() - if files_list: - delete_files(files_list, file_path) + return "Questions Uploaded Successfully" def get_test_cases(self, **kwargs): tc_list = [] @@ -408,10 +413,17 @@ class Question(models.Model): def read_json(self, file_path, user, files=None): json_file = os.path.join(file_path, "questions_dump.json") + msg = "" 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) + msg = self.load_questions(questions_list, user, file_path, files) + else: + msg = "Please upload zip file with questions_dump.json in it." + + if files: + delete_files(files, file_path) + return msg def create_demo_questions(self, user): zip_file_path = os.path.join( @@ -542,7 +554,7 @@ class Quiz(models.Model): # The start date of the quiz. start_date_time = models.DateTimeField( "Start Date and Time of the quiz", - default=timezone.now(), + default=timezone.now, null=True ) |