diff options
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index a6537e1..f098cd2 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -11,7 +11,10 @@ from django.contrib.contenttypes.models import ContentType from taggit.managers import TaggableManager from django.utils import timezone from django.core.files import File -from StringIO import StringIO +try: + from StringIO import StringIO as string_io +except ImportError: + from io import BytesIO as string_io import pytz import os import stat @@ -19,12 +22,9 @@ from os.path import join, abspath, dirname, exists import shutil import zipfile import tempfile -from file_utils import extract_files +from .file_utils import extract_files from yaksh.xmlrpc_clients import code_server - - -# The directory where user data can be saved. -OUTPUT_DIR = abspath(join(dirname(__file__), 'output')) +from django.conf import settings languages = ( @@ -180,7 +180,7 @@ class Course(models.Model): success = False return success - def __unicode__(self): + def __str__(self): return self.name ############################################################################### @@ -205,9 +205,9 @@ class Profile(models.Model): def get_user_dir(self): """Return the output directory for the user.""" - user_dir = join(OUTPUT_DIR, str(self.user.username)) + user_dir = join(settings.OUTPUT_DIR, str(self.user.username)) if not exists(user_dir): - os.mkdir(user_dir) + os.makedirs(user_dir) # Make it rwx by others. os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR @@ -273,7 +273,7 @@ class Question(models.Model): def dump_questions(self, question_ids, user): questions = Question.objects.filter(id__in=question_ids, user_id=user.id) questions_dict = [] - zip_file_name = StringIO() + zip_file_name = string_io() zip_file = zipfile.ZipFile(zip_file_name, "a") for question in questions: test_case = question.get_test_cases() @@ -367,7 +367,7 @@ class Question(models.Model): self.read_json("questions_dump.json", user) - def __unicode__(self): + def __str__(self): return self.summary @@ -421,7 +421,7 @@ class Answer(models.Model): else: self.marks = marks - def __unicode__(self): + def __str__(self): return self.answer @@ -543,7 +543,7 @@ class Quiz(models.Model): course=course) return demo_quiz - def __unicode__(self): + def __str__(self): desc = self.description or 'Quiz' return '%s: on %s for %d minutes' % (desc, self.start_date_time, self.duration) @@ -685,7 +685,7 @@ class QuestionPaper(models.Model): for question in questions: question_paper.fixed_questions.add(question) - def __unicode__(self): + def __str__(self): return "Question Paper for " + self.quiz.description ############################################################################### @@ -705,7 +705,7 @@ class QuestionSet(models.Model): def get_random_questions(self): """ Returns random questions from set of questions""" - return sample(self.questions.all(), self.num_questions) + return sample(list(self.questions.all()), self.num_questions) ############################################################################### @@ -1078,7 +1078,7 @@ class AnswerPaper(models.Model): self.update_marks('complete') return True, msg - def __unicode__(self): + def __str__(self): u = self.user q = self.question_paper.quiz return u'AnswerPaper paper of {0} {1} for quiz {2}'\ @@ -1102,7 +1102,7 @@ class StandardTestCase(TestCase): def get_field_value(self): return {"test_case": self.test_case} - def __unicode__(self): + def __str__(self): return u'Question: {0} | Test Case: {1}'.format(self.question, self.test_case ) @@ -1116,7 +1116,7 @@ class StdioBasedTestCase(TestCase): return {"expected_output": self.expected_output, "expected_input": self.expected_input} - def __unicode__(self): + def __str__(self): return u'Question: {0} | Exp. Output: {1} | Exp. Input: {2}'.format(self.question, self.expected_output, self.expected_input ) @@ -1129,7 +1129,7 @@ class McqTestCase(TestCase): def get_field_value(self): return {"options": self.options, "correct": self.correct} - def __unicode__(self): + def __str__(self): return u'Question: {0} | Correct: {1}'.format(self.question, self.correct ) |