<commit_before># -*- coding: utf-8 -*-

import logging

#from django import forms
#from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import get_user_model

LOGGER = logging.getLogger(__name__)
User = get_user_model()


class FullUserCreationForm(UserCreationForm):
    """ Like the django UserCreationForm,
        with optional first_name and last_name,
        and email too.

        .. note:: the ``username`` field from Django's ``UserCreationForm``
            is overriden by our Model's one. Thus the 30 chars limit
            doesn't apply.
    """

    class Meta:
        model = User
        # We want a different order of fields on the page.
        fields = ['first_name', 'last_name',
                  'username', 'email',
                  '<PASSWORD>', '<PASSWORD>', ]

    def save(self, commit=True):
        user = super(FullUserCreationForm, self).save(commit=False)

        user.email     = self.cleaned_data["email"]
        user.first_name = self.cleaned_data["first_name"]
        user.last_name  = self.cleaned_data["last_name"]

        if commit:
            user.save()
        return user<commit_msg>Make the FullUserCreationForm work on a fresh database which doesn't have Django's auth_user table.<commit_after># -*- coding: utf-8 -*-

import logging

from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model

LOGGER = logging.getLogger(__name__)
User = get_user_model()


class FullUserCreationForm(forms.ModelForm):
    """ Like the django UserCreationForm,
        with optional first_name and last_name,
        and email too.

        .. note:: the ``username`` field from Django's ``UserCreationForm``
            is overriden by our Model's one. Thus the 30 chars limit
            doesn't apply.
    """

    error_messages = {
        'password_mismatch': _("The two password fields didn't match."),
    }

    email = forms.EmailField()
    password1 = forms.CharField(label=_("Password"),
                                widget=forms.PasswordInput)
    password2 = forms.CharField(label=_("Password confirmation"),
                                widget=forms.PasswordInput,
                                help_text=_("Enter the same password as "
                                            "above, for verification."))

    class Meta:
        model  = User
        fields = ['first_name', 'last_name',
                  'username', 'email',
                  'password1', '<PASSWORD>', ]

    def clean_password2(self):
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'])
        return password2

    def save(self, commit=True):
        user = super(FullUserCreationForm, self).save(commit=False)

        user.set_password(self.cleaned_data["<PASSWORD>"])
        user.email      = self.cleaned_data["email"]
        user.first_name = self.cleaned_data["first_name"]
        user.last_name  = self.cleaned_data["last_name"]

        if commit:
            user.save()

        return user
{'fraction_non_alphanumeric': 0.10006027727546715, 'fraction_numerical': 0.005726341169379144, 'mean_word_length': 2.379837067209776, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1032751', 'n_tokens_mistral': 919, 'n_tokens_neox': 884, 'n_words': 238}