summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorKing2016-05-05 18:46:19 +0530
committerKing2016-05-05 18:46:19 +0530
commitd386d24aaa662f91e4314060926dc9bc02426c7d (patch)
tree28e8b0d3e39cf5d9a6ce77b42b712290f1a3baf3 /yaksh/models.py
parent8841e5ed4f8f79b7067ddb3523f4a3ec50f362b3 (diff)
parente81b13f7d94c0877801726fc85e967f36ba8bd90 (diff)
downloadonline_test-d386d24aaa662f91e4314060926dc9bc02426c7d.tar.gz
online_test-d386d24aaa662f91e4314060926dc9bc02426c7d.tar.bz2
online_test-d386d24aaa662f91e4314060926dc9bc02426c7d.zip
Merge pull request #93 from adityacp/load_dump_questions
Load dump questions
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 561b334..6e59d7a 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -173,6 +173,9 @@ class Question(models.Model):
# Tags for the Question.
tags = TaggableManager(blank=True)
+ # user for particular question
+ user = models.ForeignKey(User, related_name="user")
+
def consolidate_answer_data(self, test_cases, user_answer):
test_case_data_dict = []
question_info_dict = {}
@@ -208,6 +211,26 @@ class Question(models.Model):
return json.dumps(question_info_dict)
+ def dump_into_json(self, question_ids, user):
+ questions = Question.objects.filter(id__in = question_ids, user_id = user.id)
+ questions_dict = []
+ for question in questions:
+ q_dict = {'summary': question.summary, 'description': question.description,
+ 'points': question.points, 'test': question.test,
+ 'ref_code_path': question.ref_code_path,
+ 'options': question.options, 'language': question.language,
+ 'type': question.type, 'active': question.active,
+ 'snippet': question.snippet}
+ questions_dict.append(q_dict)
+
+ return json.dumps(questions_dict, indent=2)
+
+ def load_from_json(self, questions_list, user):
+ questions = json.loads(questions_list)
+ for question in questions:
+ question['user'] = user
+ Question.objects.get_or_create(**question)
+
def __unicode__(self):
return self.summary
@@ -487,7 +510,7 @@ class AnswerPaperManager(models.Manager):
return answerpapers.values_list('user', flat=True).distinct()
def get_latest_attempts(self, questionpaper_id):
- papers = self.get_answerpapers_for_quiz(questionpaper_id)
+ papers = self._get_answerpapers_for_quiz(questionpaper_id)
users = self._get_answerpapers_users(papers)
latest_attempts = []
for user in users: