From 51a93b42b1d7b3a94e227796aa8d4f6e97de9929 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Wed, 27 Dec 2017 17:32:21 +0530 Subject: Exercise feature in video lessons Exercise is same as quiz except for following differences: - no time limit - no marks weightage - no instruction page - skip denied for a particular time An attribute 'is_exercise' in Quiz determines whether the quiz is exercise or not. Questions contains 'min_time' attribute. For an exercise a question cannot be skipped for an allotted minimum time, after which either django or JavaScript makes Next button available. Implementation is as such due to complexity of our existing views and templates. Also, after min_time, same question with Next button is available to move on, assuming that solution is present in the video. --- yaksh/models.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index c65e9ef..839043f 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -308,6 +308,8 @@ class Quiz(models.Model): weightage = models.FloatField(default=1.0) + is_exercise = models.BooleanField(default=False) + creator = models.ForeignKey(User, null=True) objects = QuizManager() @@ -747,6 +749,8 @@ class Question(models.Model): # Check assignment upload based question grade_assignment_upload = models.BooleanField(default=False) + min_time = models.IntegerField("time in minutes", default=0) + def consolidate_answer_data(self, user_answer, user=None): question_data = {} metadata = {} @@ -1517,15 +1521,25 @@ class AnswerPaper(models.Model): def time_left(self): """Return the time remaining for the user in seconds.""" + secs = self._get_total_seconds() + total = self.question_paper.quiz.duration*60.0 + remain = max(total - secs, 0) + return int(remain) + + def time_left_on_question(self, question): + secs = self._get_total_seconds() + total = question.min_time*60.0 + remain = max(total - secs, 0) + return int(remain) + + def _get_total_seconds(self): dt = timezone.now() - self.start_time try: secs = dt.total_seconds() except AttributeError: # total_seconds is new in Python 2.7. :( secs = dt.seconds + dt.days*24*3600 - total = self.question_paper.quiz.duration*60.0 - remain = max(total - secs, 0) - return int(remain) + return secs def _update_marks_obtained(self): """Updates the total marks earned by student for this paper.""" -- cgit