<commit_before>from django.shortcuts import get_object_or_404, render, redirect

from quiz.forms import QuestionForm
from quiz.models import Quiz


def question(request, slug=None):
    if slug is None:
        question = Quiz.current().start()
        request.session['ticket'] = [request.path]
    else:
        question = get_object_or_404(Quiz.current().question_set, slug=slug)

    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:
        valid_url = ticket[-1]

    if request.method == 'POST' and valid:
        form = QuestionForm(question, request.POST)
        if form.is_valid():

            answer = form.cleaned_data['answer']
            where_to = answer.where_to()

            del ticket[cur_index + 1:]
            try:
                del ticket[ticket.index(where_to) + 1:]
            except ValueError:
                ticket.append(where_to)

            request.session['ticket'] = ticket

            return redirect(where_to)
    else:
        form = QuestionForm(question)

    return render(request, "quiz/question_detail.html", locals())


def result(request, slug=None):
    ticket = request.session['ticket']
    valid = request.path in ticket

    if valid:
        cur_index = ticket.index(request.path)
        if cur_index:
            previous_url = ticket[cur_index - 1]
    else:
        valid_url = ticket[-1]


    result = get_object_or_404(Quiz.current().result_set, slug=slug)
    return render(request, "quiz/result_detail.html", locals())
<commit_msg>session mgmt fix<commit_after>from django.shortcuts import get_object_or_404, render, redirect

from quiz.forms import QuestionForm
from quiz.models import Quiz


def question(request, slug=None):
    if slug is None:
        question = Quiz.current().start()
        request.session['ticket'] = [request.path]
    else:
        question = get_object_or_404(Quiz.current().question_set, slug=slug)

    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]
    else:
        valid_url = ticket[-1]

    if request.method == 'POST' and valid:
        form = QuestionForm(question, request.POST)
        if form.is_valid():

            answer = form.cleaned_data['answer']
            where_to = answer.where_to()

            del ticket[cur_index + 1:]
            try:
                del ticket[ticket.index(where_to) + 1:]
            except ValueError:
                ticket.append(where_to)

            request.session['ticket'] = ticket

            return redirect(where_to)
    else:
        form = QuestionForm(question)

    return render(request, "quiz/question_detail.html", locals())


def result(request, slug=None):
    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]
    else:
        valid_url = ticket[-1]


    result = get_object_or_404(Quiz.current().result_set, slug=slug)
    return render(request, "quiz/result_detail.html", locals())

{'fraction_non_alphanumeric': 0.10682492581602374, 'fraction_numerical': 0.008902077151335312, 'mean_word_length': 2.4538934426229506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4580905', 'n_tokens_mistral': 1045, 'n_tokens_neox': 971, 'n_words': 225}