summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authoradityacp2016-08-30 22:44:16 +0530
committeradityacp2016-08-30 22:44:16 +0530
commit4eb9778454dc5ecec99ccf951f012a69582b0ca3 (patch)
tree2020c75240b57c2d91664ed2d5ed28ecb4e0edef /yaksh
parentd398cf7f30fe1f5e09fd0424824eff614374652d (diff)
downloadonline_test-4eb9778454dc5ecec99ccf951f012a69582b0ca3.tar.gz
online_test-4eb9778454dc5ecec99ccf951f012a69582b0ca3.tar.bz2
online_test-4eb9778454dc5ecec99ccf951f012a69582b0ca3.zip
added read_json func in Question model
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index e296524..4fb77fd 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -293,15 +293,17 @@ class Question(models.Model):
files_list = []
for f in files:
zip_file.write(f.file.path, (os.path.basename(f.file.path)))
- files_list.append(os.path.basename(f.file.path))
+ files_list.append(((os.path.basename(f.file.path)), f.extract))
return files_list
def _add_files_to_db(self, file_names):
- for file_name in file_names:
+ for file_name, extract in file_names:
que_file = open(file_name, 'r')
#Converting to Python file object with some Django-specific additions
django_file = File(que_file)
- f = FileUpload.objects.get_or_create(file=django_file, question=self)
+ f = FileUpload.objects.get_or_create(file=django_file,
+ question=self,
+ extract=extract)
os.remove(file_name)
def _add_json_to_zip(self, zip_file, q_dict):
@@ -314,6 +316,13 @@ class Question(models.Model):
zip_file.close()
shutil.rmtree(tmp_file_path)
+ def read_json(self, json_file, user):
+ 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)
+ os.remove(json_file)
+
def __unicode__(self):
return self.summary