<commit_before>from django.contrib.auth import authenticate, login
from django.contrib.auth.forms import UserCreationForm
from django.forms import BooleanField
from django.http import HttpResponseRedirect
from django.views.generic.edit import CreateView


class UserWithTermsForm(UserCreationForm):
    """
    Subclass Django's UserCreationForm and add a `terms` field to it to add
    validation for the Terms of Use checkbox.
    """
    terms = BooleanField()

    class Meta(UserCreationForm.Meta):
        fields = UserCreationForm.Meta.fields + ('email', 'terms',)


class UserCreateView(CreateView):
    """
    A view that creates a new user, logs them in, and redirects them to the
    root URL.
    """
    form_class = UserWithTermsForm
    template_name = 'home.html'

    def form_valid(self, form):
        form.save()

        user = authenticate(username=form.cleaned_data.get('username'),
                            password=form.cleaned_data.get('<PASSWORD>'))

        if user is not None:
            login(self.request, user)

        return HttpResponseRedirect('/')
<commit_msg>Add explanatory comment<commit_after>from django.contrib.auth import authenticate, login
from django.contrib.auth.forms import UserCreationForm
from django.forms import BooleanField
from django.http import HttpResponseRedirect
from django.views.generic.edit import CreateView


class UserWithTermsForm(UserCreationForm):
    """
    Subclass Django's UserCreationForm and add a `terms` field to it to add
    validation for the Terms of Use checkbox.
    """
    terms = BooleanField()

    class Meta(UserCreationForm.Meta):
        # The default form doesn't include the email address so add it here too
        fields = UserCreationForm.Meta.fields + ('email', 'terms',)


class UserCreateView(CreateView):
    """
    A view that creates a new user, logs them in, and redirects them to the
    root URL.
    """
    form_class = UserWithTermsForm
    template_name = 'home.html'

    def form_valid(self, form):
        form.save()

        user = authenticate(username=form.cleaned_data.get('username'),
                            password=form.cleaned_data.get('<PASSWORD>'))

        if user is not None:
            login(self.request, user)

        return HttpResponseRedirect('/')

{'fraction_non_alphanumeric': 0.08797909407665505, 'fraction_numerical': 0.0, 'mean_word_length': 3.1687840290381124, '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': '1508232', 'n_tokens_mistral': 634, 'n_tokens_neox': 603, 'n_words': 193}