<commit_before>from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth import authenticate, login, logout

from .forms import CreateListForm

from django.contrib.auth.models import User
from .models import Lister, Item

def index(request):
    lists = Lister.objects.filter(public=True)
    form = CreateListForm(authenticated=request.user.is_authenticated())
    context = {'lists': lists, 'form': form}

    if request.method == 'GET':
        if request.user.is_authenticated():
            context['user'] = request.user
            context['lists'] = request.user.lister_set.all()

    elif request.method == 'POST':
        username = request.POST['user']
        password = request.POST['<PASSWORD>']

        # Check for existing user and authenticate
        try:
            User.objects.get(username=username)
            user = authenticate(username=username, password=password)

            if user is not None:
                login(request, user)
                context['user'] = request.user
                context['lists'] = request.user.lister_set.all()

                return HttpResponseRedirect(reverse('lists:index'))

        # User does not exist, create new
        except ObjectDoesNotExist:
            user = User(username=username)
            user.set_password(password)
            user.save()

            user = authenticate(username=username, password=password)

            if user is not None:
                login(request, user)
                context['user'] = request.user
                context['lists'] = request.user.lister_set.all()

    return render(request, 'lists/login.html', context)


def create(request):
    if request.method == "POST":
        form = CreateListForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data['name']
            public = form.cleaned_data['public']

            lister = Lister(list_name=name, public=public)
            lister.save()

            return HttpResponseRedirect(reverse('lists:lister', args=(lister.id,)))

        else:
            form = CreateListForm()
            context = {'form': form}
<commit_msg>use redirect for all index post calls<commit_after>from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth import authenticate, login, logout

from .forms import CreateListForm

from django.contrib.auth.models import User
from .models import Lister, Item

def index(request):
    lists = Lister.objects.filter(public=True)
    form = CreateListForm(authenticated=request.user.is_authenticated())
    context = {'lists': lists, 'form': form}

    if request.method == 'GET':
        if request.user.is_authenticated():
            context['user'] = request.user
            context['lists'] = request.user.lister_set.all()

    elif request.method == 'POST':
        username = request.POST['user']
        password = request.POST['<PASSWORD>']

        # Check for existing user and authenticate
        try:
            User.objects.get(username=username)
            user = authenticate(username=username, password=password)

            if user is not None:
                login(request, user)
                context['user'] = request.user
                context['lists'] = request.user.lister_set.all()

        # User does not exist, create new
        except ObjectDoesNotExist:
            user = User(username=username)
            user.set_password(password)
            user.save()

            user = authenticate(username=username, password=password)

            if user is not None:
                login(request, user)
                context['user'] = request.user
                context['lists'] = request.user.lister_set.all()

        return HttpResponseRedirect(reverse('lists:index'))

    return render(request, 'lists/login.html', context)


def create(request):
    if request.method == "POST":
        form = CreateListForm(request.POST)

        if form.is_valid():
            name = form.cleaned_data['name']
            public = form.cleaned_data['public']

            lister = Lister(list_name=name, public=public)
            lister.save()

            return HttpResponseRedirect(reverse('lists:lister', args=(lister.id,)))

        else:
            form = CreateListForm()
            context = {'form': form}

{'fraction_non_alphanumeric': 0.10480727587700303, 'fraction_numerical': 0.00129926375054136, 'mean_word_length': 2.51254752851711, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '1739467', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1192, 'n_words': 292}