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
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
def delete(self, question_uuid): """ DELETE handler """ Question.objects(uuid=question_uuid).delete()
def get(self, question_uuid): """ GET handler """ return Question.objects(uuid=question_uuid).first()
def get(self, course_uuid): """ Retrieves the list of questions for the course """ return list(Question.objects(course=course_uuid).all())