1
0

vault backup: 2025-12-22 02:56:57
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m13s

This commit is contained in:
2025-12-22 02:56:57 +01:00
parent 3ae6c10557
commit 5a2b99c99a
26 changed files with 208 additions and 22 deletions

View File

@@ -2,23 +2,46 @@ from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.http import require_http_methods
from .models import Question, QuizResult
from .models import Question, QuizResult, Tag
def handle_tag_filter(request):
tag_slug = request.GET.get('tag')
if tag_slug is not None:
if tag_slug == "":
if 'quiz_tag' in request.session:
del request.session['quiz_tag']
else:
request.session['quiz_tag'] = tag_slug
def index(request):
handle_tag_filter(request)
total_questions = Question.objects.count()
answered_count = QuizResult.objects.filter(user=request.quiz_user).count()
context = {
'total_questions': total_questions,
'answered_count': answered_count,
'tags': Tag.objects.all(),
'current_tag': request.session.get('quiz_tag'),
}
return render(request, 'index.html', context)
def get_next_question(request):
# Handle tag filtering
handle_tag_filter(request)
current_tag = request.session.get('quiz_tag')
answered_ids = QuizResult.objects.filter(user=request.quiz_user).values_list('question_id', flat=True)
next_question = Question.objects.exclude(id__in=answered_ids).first()
questions = Question.objects.exclude(id__in=answered_ids)
if current_tag:
questions = questions.filter(tags__slug=current_tag)
next_question = questions.first()
if not next_question:
return render(request, 'partials/complete.html')