<commit_before>from django import forms
from registration.forms import RegistrationForm
from main.models import UserProfile
from registration.models import RegistrationProfile
from country_field import COUNTRIES

class RegistrationFormUserProfile(RegistrationForm):
    username = forms.CharField(widget=forms.TextInput(), max_length=30)
    email = forms.CharField(widget=forms.TextInput(), max_length=30)
    name = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    city = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    country = forms.ChoiceField(widget=forms.Select(), required=False, choices=COUNTRIES, initial='ZZ')
    organization = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    home_page = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    twitter = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)

    def save(self, profile_callback=None):
        new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'].lower(),
                password=<PASSWORD>['<PASSWORD>'],
                email=self.cleaned_data['email'])

        new_profile = UserProfile(user=new_user, name=self.cleaned_data['name'],
                city=self.cleaned_data['city'],
                country=self.cleaned_data['country'],
                organization=self.cleaned_data['organization'],
                home_page=self.cleaned_data['home_page'],
                twitter=self.cleaned_data['twitter'])
        new_profile.save()

        return new_user
<commit_msg>check user uniqueness<commit_after>from django import forms
from django.contrib.auth.models import User
from registration.forms import RegistrationForm
from main.models import UserProfile
from registration.models import RegistrationProfile
from country_field import COUNTRIES

class RegistrationFormUserProfile(RegistrationForm):
    _reserved_usernames = [
        'forms',
        'accounts'
    ]

    username = forms.CharField(widget=forms.TextInput(), max_length=30)
    email = forms.CharField(widget=forms.TextInput(), max_length=30)
    name = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    city = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    country = forms.ChoiceField(widget=forms.Select(), required=False, choices=COUNTRIES, initial='ZZ')
    organization = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    home_page = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)
    twitter = forms.CharField(widget=forms.TextInput(), required=False, max_length=255)

    def clean_username(self):
        username = self.cleaned_data['username'].lower()
        if username in self._reserved_usernames:
            raise forms.ValidationError(u'%s is a reserved name, please choose another' % username)
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            return username
        raise forms.ValidationError(u'%s already exists' % username )

    def save(self, profile_callback=None):
        new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
                password=<PASSWORD>.cleaned_data['<PASSWORD>'],
                email=self.cleaned_data['email'])

        new_profile = UserProfile(user=new_user, name=self.cleaned_data['name'],
                city=self.cleaned_data['city'],
                country=self.cleaned_data['country'],
                organization=self.cleaned_data['organization'],
                home_page=self.cleaned_data['home_page'],
                twitter=self.cleaned_data['twitter'])
        new_profile.save()

        return new_user

{'fraction_non_alphanumeric': 0.11122688200052097, 'fraction_numerical': 0.00989841104454285, 'mean_word_length': 4.072655217965654, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3043927', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1036, 'n_words': 181}