summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 36e859c..50a5cc2 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -317,7 +317,7 @@ class Quiz(models.Model):
attempts_allowed = models.IntegerField(default=1, choices=attempts)
time_between_attempts = models.FloatField(
- "Time Between Quiz Attempts in hours"
+ "Time Between Quiz Attempts in hours", default=0.0
)
is_trial = models.BooleanField(default=False)
@@ -387,6 +387,20 @@ class Quiz(models.Model):
course=course, passed=False
).values_list("user", flat=True).distinct().count()
+ def get_answerpaper_status(self, user, course):
+ try:
+ qp = self.questionpaper_set.get().id
+ except QuestionPaper.DoesNotExist:
+ qp = None
+ ans_ppr = AnswerPaper.objects.filter(
+ user=user, course=course, question_paper=qp
+ ).order_by("-attempt_number")
+ if ans_ppr.exists():
+ status = ans_ppr.first().status
+ else:
+ status = "not attempted"
+ return status
+
def _create_quiz_copy(self, user):
question_papers = self.questionpaper_set.all()
new_quiz = self
@@ -425,6 +439,8 @@ class LearningUnit(models.Model):
if course_status.exists():
if self in course_status.first().completed_units.all():
state = "completed"
+ elif self.type == "quiz":
+ state = self.quiz.get_answerpaper_status(user, course)
elif course_status.first().current_unit == self:
state = "inprogress"
return state
@@ -1373,11 +1389,18 @@ class QuestionPaper(models.Model):
)
if last_attempt:
time_lag = (timezone.now() - last_attempt.start_time).total_seconds() / 3600
- return time_lag >= self.quiz.time_between_attempts
+ can_attempt = time_lag >= self.quiz.time_between_attempts
+ msg = "You cannot start the next attempt for this quiz before {0} hour(s)".format(
+ self.quiz.time_between_attempts
+ ) if not can_attempt else None
+ return can_attempt, msg
else:
- return True
+ return True, None
else:
- return False
+ msg = "You cannot attempt {0} quiz more than {1} time(s)".format(
+ self.quiz.description, self.quiz.attempts_allowed
+ )
+ return False, msg
def create_demo_quiz_ppr(self, demo_quiz, user):
question_paper = QuestionPaper.objects.create(quiz=demo_quiz,