X-Git-Url: https://git.mdrn.pl/koed-quiz.git/blobdiff_plain/2c2b8f122dd789a089ac5054e112f59874c01a70..ff9d51a145c153222e088a7c08d540ea61005395:/apps/quiz/views.py?ds=inline diff --git a/apps/quiz/views.py b/apps/quiz/views.py index 7160759..8fa7280 100644 --- a/apps/quiz/views.py +++ b/apps/quiz/views.py @@ -11,14 +11,14 @@ def question(request, slug=None): else: question = get_object_or_404(Quiz.current().question_set, slug=slug) - ticket = request.session.get('ticket') + ticket = request.session.get('ticket', []) valid = request.path in ticket - print ticket, valid + if valid: 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: @@ -44,9 +44,16 @@ def question(request, slug=None): def result(request, slug=None): - ticket = request.session['ticket'] + ticket = request.session.get('ticket', []) valid = request.path in ticket + if valid: + cur_index = ticket.index(request.path) + if cur_index: + previous_url = ticket[cur_index - 1] + elif ticket: + valid_url = ticket[-1] + result = get_object_or_404(Quiz.current().result_set, slug=slug) return render(request, "quiz/result_detail.html", locals())