<commit_before>from django.conf import settings
from django.shortcuts import redirect
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.http import HttpResponseBadRequest
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_POST
from django.views.generic.simple import direct_to_template

from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

from lazysignup.decorators import allow_lazy_user

@allow_lazy_user
def convert(request, form_class=UserCreationForm, redirect_field_name='redirect_to'):
    """ Convert a temporary user to a real one. Reject users who don't
    appear to be temporary users (ie. they have a usable password)
    """
    redirect_to = 'lazysignup_convert_done'
    
    # If we've got an anonymous user, redirect to login
    if request.user.is_anonymous():
        return HttpResponseRedirect(settings.LOGIN_URL)
    
    if request.method == 'POST':
        redirect_to = request.POST.get(redirect_field_name) or redirect_to
        # If the user already has a usable password, return a Bad Request to
        # an Ajax client, or just redirect back for a regular client.
        if request.user.has_usable_password():
            if request.is_ajax():
                return HttpResponseBadRequest(content=_(u"Already converted."))
            else:
                return redirect(redirect_to)
            
        # Looks OK - proceed with validation.
        form = form_class(request.POST, instance=request.user)
        if form.is_valid():
            user = form.save()
        
            # Re-log the user in, as they'll now not be authenticatable with the Lazy 
            # backend
            login(request, authenticate(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['<PASSWORD>'],
                ))
        
            # If we're being called via AJAX, then we just return a 200 directly<commit_msg>Parameterise the anon redirect URL<commit_after>from django.conf import settings
from django.shortcuts import redirect
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.http import HttpResponseBadRequest
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_POST
from django.views.generic.simple import direct_to_template

from django.contrib.auth import authenticate
from django.contrib.auth import login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

from lazysignup.decorators import allow_lazy_user

@allow_lazy_user
def convert(request, form_class=UserCreationForm, redirect_field_name='redirect_to',
            anonymous_redirect=settings.LOGIN_URL):
    """ Convert a temporary user to a real one. Reject users who don't
    appear to be temporary users (ie. they have a usable password)
    """
    redirect_to = 'lazysignup_convert_done'
    
    # If we've got an anonymous user, redirect to login
    if request.user.is_anonymous():
        return HttpResponseRedirect(anonymous_redirect)
    
    if request.method == 'POST':
        redirect_to = request.POST.get(redirect_field_name) or redirect_to
        # If the user already has a usable password, return a Bad Request to
        # an Ajax client, or just redirect back for a regular client.
        if request.user.has_usable_password():
            if request.is_ajax():
                return HttpResponseBadRequest(content=_(u"Already converted."))
            else:
                return redirect(redirect_to)
            
        # Looks OK - proceed with validation.
        form = form_class(request.POST, instance=request.user)
        if form.is_valid():
            user = form.save()
        
            # Re-log the user in, as they'll now not be authenticatable with the Lazy 
            # backend
            login(request, authenticate(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['<PASSWORD>'],
                ))
        
            # If we're being called via AJAX, then we just return a 200 directly
{'fraction_non_alphanumeric': 0.06637168141592921, 'fraction_numerical': 0.001327433628318584, 'mean_word_length': 3.007978723404255, 'pattern_counts': {'":': 0, '<': 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': '4850309', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1146, 'n_words': 380}