summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authormahesh2017-03-20 17:04:46 +0530
committermahesh2017-03-20 17:04:46 +0530
commitb5daabb45621ac47c98382303800cb7a240827c2 (patch)
treef3369879e3170a2a5e831fe6763a4615d27e2bec /yaksh/models.py
parentac292ed1099b49f9d0e8a7ed3699bacdd8031de3 (diff)
parent23ecd8fa33e7fa2e953aa9715ae45a2869a044a0 (diff)
downloadonline_test-b5daabb45621ac47c98382303800cb7a240827c2.tar.gz
online_test-b5daabb45621ac47c98382303800cb7a240827c2.tar.bz2
online_test-b5daabb45621ac47c98382303800cb7a240827c2.zip
Merge branch 'master' of https://github.com/fossee/online_test into fill_in_the_blanks
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index d583f7b..be741b1 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
@@ -77,7 +79,7 @@ test_status = (
def get_assignment_dir(instance, filename):
return os.sep.join((
- instance.user.user, instance.assignmentQuestion.id, filename
+ instance.user.user.username, str(instance.assignmentQuestion.id), filename
))
@@ -323,7 +325,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')
@@ -340,8 +346,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 = []
@@ -409,10 +414,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(
@@ -543,7 +555,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
)