Add a makefile.
[koed-quiz.git] / apps / quiz / views.py
index 830798d..700371f 100644 (file)
@@ -1,3 +1,6 @@
+# This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
 from django.shortcuts import get_object_or_404, render, redirect
 
 from quiz.forms import QuestionForm
@@ -6,10 +9,10 @@ from quiz.models import Quiz
 
 def question(request, slug=None):
     if slug is None:
-        question = Quiz.current().start()
+        question = request.current_quiz.start()
         request.session['ticket'] = [request.path]
     else:
-        question = get_object_or_404(Quiz.current().question_set, slug=slug)
+        question = get_object_or_404(request.current_quiz.question_set, slug=slug)
 
     ticket = request.session.get('ticket', [])
     valid = request.path in ticket
@@ -18,7 +21,7 @@ def question(request, slug=None):
         cur_index = ticket.index(request.path)
         if cur_index:
             previous_url = ticket[cur_index - 1]
-    else:
+    elif ticket:
         valid_url = ticket[-1]
 
     if request.method == 'POST' and valid:
@@ -51,10 +54,9 @@ def result(request, slug=None):
         cur_index = ticket.index(request.path)
         if cur_index:
             previous_url = ticket[cur_index - 1]
-    else:
+    elif ticket:
         valid_url = ticket[-1]
 
-
-    result = get_object_or_404(Quiz.current().result_set, slug=slug)
+    result = get_object_or_404(request.current_quiz.result_set, slug=slug)
     return render(request, "quiz/result_detail.html", locals())