Example #1
0
 def get_question(self):
     """
     Selects a question at random
     """
     sample = {'$sample': {'size': 1}}
     result = Question.objects(course=self.course).aggregate(sample)
     document = next(result, None)
     return Question.objects.get(uuid=document['_id']) if document else None
Example #2
0
 def get_question(self):
     """
     Selects the closest question to the student's current ability level
     """
     if not self.level:
         self._fetch_level()
     # TODO: Avoid repetition
     question = Question.objects(
         course=self.course,
         level__gte=self.level).order_by('level').first()
     if not question:
         question = Question.objects.order_by('-level').first()
     return question
Example #3
0
 def delete(self, question_uuid):
     """
     DELETE handler
     """
     Question.objects(uuid=question_uuid).delete()
Example #4
0
 def get(self, question_uuid):
     """
     GET handler
     """
     return Question.objects(uuid=question_uuid).first()
Example #5
0
 def get(self, course_uuid):
     """
     Retrieves the list of questions for the course
     """
     return list(Question.objects(course=course_uuid).all())