All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
30 lines
842 B
Python
30 lines
842 B
Python
from django.db.models import Q
|
|
from quiz.models import Question
|
|
|
|
|
|
def get_session_questions(session):
|
|
"""Helper to get filtered questions for a session"""
|
|
questions = Question.objects.all()
|
|
|
|
if session.course:
|
|
questions = questions.filter(exam__course=session.course)
|
|
|
|
if session.tags.exists():
|
|
questions = questions.filter(tags__in=session.tags.all())
|
|
|
|
if session.exams.exists():
|
|
questions = questions.filter(exam__in=session.exams.all())
|
|
|
|
if session.question_types:
|
|
q_objs = Q()
|
|
if 'single' in session.question_types:
|
|
q_objs |= ~Q(correct_answer__contains=',')
|
|
if 'multi' in session.question_types:
|
|
q_objs |= Q(correct_answer__contains=',')
|
|
|
|
if q_objs:
|
|
questions = questions.filter(q_objs)
|
|
|
|
return questions.distinct()
|
|
|