diff options
author | prathamesh | 2014-09-23 14:44:47 +0530 |
---|---|---|
committer | prathamesh | 2014-09-23 14:44:47 +0530 |
commit | 0808861705c08aede6c0dc9e07ac891911a7bbfb (patch) | |
tree | 729d56c50370070b9e08f44f68a3ce91f9235534 /testapp/exam/models.py | |
parent | 962cee1705509bb595cda51d104ef1ef7cf0b4fd (diff) | |
download | online_test-0808861705c08aede6c0dc9e07ac891911a7bbfb.tar.gz online_test-0808861705c08aede6c0dc9e07ac891911a7bbfb.tar.bz2 online_test-0808861705c08aede6c0dc9e07ac891911a7bbfb.zip |
Models and views modified.
Added number of attempts option for quiz.
Also days lag between two attempts.
added test status and attempt number for the test.
Removed profile foreign key from answer paper models
since user foreign key is present in the answer paper model.
Urls slightly modified to include attemt number for a given quiz.
Diffstat (limited to 'testapp/exam/models.py')
-rw-r--r-- | testapp/exam/models.py | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/testapp/exam/models.py b/testapp/exam/models.py index 196ee73..259f875 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -31,7 +31,15 @@ question_types = ( ("mcc", "Multiple Correct Choices"), ("code", "Code"), ) +attempts = [(i, i) for i in range(1, 6)] +attempts.append((-1, 'Infinite')) +days_between_attempts = ((j, j) for j in range(401)) + +test_status = ( + ('inprogress', 'Inprogress'), + ('completed', 'Completed'), + ) ############################################################################### class Question(models.Model): @@ -125,6 +133,12 @@ class Quiz(models.Model): # Programming language for a quiz language = models.CharField(max_length=20, choices=languages) + # Number of attempts for the quiz + attempts_allowed = models.IntegerField(default=1, choices=attempts) + + time_between_attempts = models.IntegerField("Number of Days",\ + choices=days_between_attempts) + class Meta: verbose_name_plural = "Quizzes" @@ -171,9 +185,9 @@ class QuestionPaper(models.Model): questions += question_set.get_random_questions() return questions - def make_answerpaper(self, user, ip): + def make_answerpaper(self, user, ip, attempt_no): """Creates an answer paper for the user to attempt the quiz""" - ans_paper = AnswerPaper(user=user, profile=user.profile, user_ip=ip) + ans_paper = AnswerPaper(user=user, user_ip=ip, attempt_number=attempt_no) ans_paper.start_time = datetime.datetime.now() ans_paper.end_time = ans_paper.start_time \ + datetime.timedelta(minutes=self.quiz.duration) @@ -214,10 +228,6 @@ class AnswerPaper(models.Model): # The user taking this question paper. user = models.ForeignKey(User) - # The user's profile, we store a reference to make it easier to access the - # data. - profile = models.ForeignKey(Profile) - # All questions that remain to be attempted for a particular Student # (a list of ids separated by '|') questions = models.CharField(max_length=128) @@ -225,6 +235,9 @@ class AnswerPaper(models.Model): # The Quiz to which this question paper is attached to. question_paper = models.ForeignKey(QuestionPaper) + # The attempt number for the question paper. + attempt_number = models.IntegerField() + # The time when this paper was started by the user. start_time = models.DateTimeField() @@ -252,6 +265,10 @@ class AnswerPaper(models.Model): # Result of the quiz, True if student passes the exam. passed = models.NullBooleanField() + # Status of the quiz attempt + status = models.CharField(max_length=20, choices=test_status,\ + default='inprogress') + def current_question(self): """Returns the current active question to display.""" qs = self.questions.split('|') @@ -343,6 +360,10 @@ class AnswerPaper(models.Model): else: self.passed = False + def update_status(self): + """ Sets status to completed """ + self.status = 'completed' + def get_question_answers(self): """ Return a dictionary with keys as questions and a list of the |