diff options
author | Prabhu Ramachandran | 2018-01-19 22:25:39 +0530 |
---|---|---|
committer | GitHub | 2018-01-19 22:25:39 +0530 |
commit | 0824e419c6aa52bb9b788db1208dc2b70c104d8f (patch) | |
tree | 7405617e9351e724db5269e55d915ad6cbaff01d /yaksh/models.py | |
parent | 1445358b4ee548edd16a8d42026b080b7d92a0c4 (diff) | |
parent | bfc3f08d5da08f774e76aa169a50f8e7847ff6ed (diff) | |
download | online_test-0824e419c6aa52bb9b788db1208dc2b70c104d8f.tar.gz online_test-0824e419c6aa52bb9b788db1208dc2b70c104d8f.tar.bz2 online_test-0824e419c6aa52bb9b788db1208dc2b70c104d8f.zip |
Merge pull request #424 from adityacp/fix_question_paper_edit
Fix Question Paper and Course related issue
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index f0d1b2e..1e45851 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1196,13 +1196,14 @@ class QuestionPaper(models.Model): return ans_paper - def _is_attempt_allowed(self, user): + def _is_attempt_allowed(self, user, course_id): attempts = AnswerPaper.objects.get_total_attempt(questionpaper=self, - user=user) + user=user, + course_id=course_id) return attempts != self.quiz.attempts_allowed def can_attempt_now(self, user, course_id): - if self._is_attempt_allowed(user): + if self._is_attempt_allowed(user, course_id): last_attempt = AnswerPaper.objects.get_user_last_attempt( user=user, questionpaper=self, course_id=course_id ) @@ -1280,10 +1281,11 @@ class QuestionSet(models.Model): ############################################################################### class AnswerPaperManager(models.Manager): - def get_all_questions(self, questionpaper_id, attempt_number, + def get_all_questions(self, questionpaper_id, attempt_number, course_id, status='completed'): ''' Return a dict of question id as key and count as value''' papers = self.filter(question_paper_id=questionpaper_id, + course_id=course_id, attempt_number=attempt_number, status=status) all_questions = list() questions = list() @@ -1294,9 +1296,10 @@ class AnswerPaperManager(models.Manager): return Counter(questions) def get_all_questions_answered(self, questionpaper_id, attempt_number, - status='completed'): + course_id, status='completed'): ''' Return a dict of answered question id as key and count as value''' papers = self.filter(question_paper_id=questionpaper_id, + course_id=course_id, attempt_number=attempt_number, status=status) questions_answered = list() for paper in papers: @@ -1334,15 +1337,17 @@ class AnswerPaperManager(models.Manager): ).count() def get_question_statistics(self, questionpaper_id, attempt_number, - status='completed'): + course_id, status='completed'): ''' Return dict with question object as key and list as value The list contains two value, first the number of times a question was answered correctly, and second the number of times a question appeared in a quiz''' question_stats = {} questions_answered = self.get_all_questions_answered(questionpaper_id, - attempt_number) - questions = self.get_all_questions(questionpaper_id, attempt_number) + attempt_number, + course_id) + questions = self.get_all_questions(questionpaper_id, attempt_number, + course_id) all_questions = Question.objects.filter( id__in=set(questions), active=True @@ -1391,8 +1396,9 @@ class AnswerPaperManager(models.Manager): def get_user_answerpapers(self, user): return self.filter(user=user) - def get_total_attempt(self, questionpaper, user): - return self.filter(question_paper=questionpaper, user=user).count() + def get_total_attempt(self, questionpaper, user, course_id): + return self.filter(question_paper=questionpaper, user=user, + course_id=course_id).count() def get_users_for_questionpaper(self, questionpaper_id, course_id): return self._get_answerpapers_for_quiz(questionpaper_id, course_id, |