diff options
author | prathamesh | 2016-03-16 12:05:27 +0530 |
---|---|---|
committer | prathamesh | 2016-03-16 15:05:29 +0530 |
commit | aab320d8867a15569ddd0da029f13ea5740f6518 (patch) | |
tree | 2f0f84db2fd437124c6dce970cd7dd8140d79e3a /yaksh/models.py | |
parent | ef3cd39ebdf9d9fc9011ba4bc470ec5018bb8077 (diff) | |
download | online_test-aab320d8867a15569ddd0da029f13ea5740f6518.tar.gz online_test-aab320d8867a15569ddd0da029f13ea5740f6518.tar.bz2 online_test-aab320d8867a15569ddd0da029f13ea5740f6518.zip |
A moderator can download csv file for a given question paper.
csv includes the latest attempt for the quiz/questionpaper.
It contains user details and marks for the quiz.
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 1bbd035..7bd0a9e 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -414,6 +414,23 @@ class AnswerPaperManager(models.Manager): question_stats[question] = [0, questions[question.id]] return question_stats + def get_answerpapers_for_quiz(self, questionpaper_id): + return self.filter(question_paper_id=questionpaper_id) + + def _get_answerpapers_users(self, answerpapers): + return answerpapers.values_list('user', flat=True).distinct() + + def get_latest_attempts(self, questionpaper_id): + papers = self.get_answerpapers_for_quiz(questionpaper_id) + users = self._get_answerpapers_users(papers) + latest_attempts = [] + for user in users: + latest_attempts.append(self._get_latest_attempt(papers, user)) + return latest_attempts + + def _get_latest_attempt(self, answerpapers, user_id): + return answerpapers.filter(user_id=user_id).order_by('-attempt_number')[0] + ############################################################################### class AnswerPaper(models.Model): |