summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authormaheshgudi2016-08-03 15:16:08 +0530
committermaheshgudi2016-08-03 15:16:08 +0530
commit40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb (patch)
tree7885b674d2deb064137f1f501ed1707bfd54daf8 /yaksh/models.py
parent1b71abc9437d721a41f017db406f312755f5a4c4 (diff)
parent2b03aeb36fa333ea1644a248c742cf0c1df12a5f (diff)
downloadonline_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.gz
online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.bz2
online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.zip
rebase changes with stdio evaluator
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 3fd7508..bdd3875 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -11,6 +11,8 @@ from django.contrib.contenttypes.models import ContentType
from taggit.managers import TaggableManager
from django.utils import timezone
import pytz
+import os
+import shutil
languages = (
("python", "Python"),
@@ -62,6 +64,9 @@ def has_profile(user):
""" check if user has profile """
return True if hasattr(user, 'profile') else False
+def get_upload_dir(instance, filename):
+ return "question_%s/%s" % (instance.question.id, filename)
+
###############################################################################
class CourseManager(models.Manager):
@@ -216,6 +221,10 @@ class Question(models.Model):
question_data['test_case_data'] = test_case_data
question_data['user_answer'] = user_answer
+ files = FileUpload.objects.filter(question=self)
+ if files:
+ question_data['file_paths'] = [(file.file.path, file.extract)
+ for file in files]
return json.dumps(question_data)
@@ -252,7 +261,7 @@ class Question(models.Model):
model=self.test_case_type
)
test_cases = test_case_ctype.get_all_objects_for_this_type(
- question=self,
+ question=self,
**kwargs
)
@@ -263,7 +272,7 @@ class Question(models.Model):
model=self.test_case_type
)
test_case = test_case_ctype.get_object_for_this_type(
- question=self,
+ question=self,
**kwargs
)
@@ -274,6 +283,27 @@ class Question(models.Model):
###############################################################################
+class FileUpload(models.Model):
+ file = models.FileField(upload_to=get_upload_dir, blank=True)
+ question = models.ForeignKey(Question, related_name="question")
+ extract = models.BooleanField(default=False)
+
+ def remove(self):
+ if os.path.exists(self.file.path):
+ os.remove(self.file.path)
+ if os.listdir(os.path.dirname(self.file.path)) == []:
+ os.rmdir(os.path.dirname(self.file.path))
+ self.delete()
+
+ def set_extract_status(self):
+ if self.extract:
+ self.extract = False
+ else:
+ self.extract = True
+ self.save()
+
+
+###############################################################################
class Answer(models.Model):
"""Answers submitted by the users."""