<commit_before>from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.contrib.localflavor.us.forms import USStateField, USZipCodeField
from django.contrib.localflavor.us.us_states import STATE_CHOICES
from django.forms import ModelForm
from alert.userHandling.models import UserProfile


class ProfileForm(ModelForm):
    STATE_CHOICES = list(STATE_CHOICES)
    STATE_CHOICES.insert(0, ('', '---------'))
    state = USStateField(
        widget=forms.Select(
            choices=STATE_CHOICES,
            attrs={'class': 'span-5'}
        ),
        required=False,
    )
    zip_code = USZipCodeField(
        widget=forms.TextInput(
            attrs={'class': 'span-4'}
        ),
        required=False,
    )

    class Meta:
        model = UserProfile
        fields = (
            'employer',
            'address1',
            'address2',
            'city',
            'state',
            'zip_code',
            'wants_newsletter',
            'barmembership',
            'plaintext_preferred',
        )
        widgets = {
            'employer': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
            'barmembership': forms.SelectMultiple(
                attrs={'class': 'span-9',
                       'size': '8'}
            ),
            'address1': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
            'address2': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
            'city': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
        }


class UserForm(ModelForm):
    email = forms.EmailField(
        required=True,
        widget=forms.TextInput(
            attrs={'class': 'span-9'}
        )
    )

    def clean_email(self):
        """ensures unique email addresses"""
        email = self.cleaned_data.get('email')
        if email and User.objects.filter(email=email).count():
            raise forms.ValidationError(u'This email address is already in use.')
        return email

    class Meta:
        model = User
        fields = (
            'first_name',
            'last_name',
            'email',
        )
        widgets = {
            'first_name': forms.TextInput(
                attrs={'class': 'span-4'}
            ),
            'last_name': forms.TextInput(
                attrs={'class': 'span-5'}
            ),
        }


class UserCreationFormExtended(UserCreationForm):
    def __init__(self, *args, **kwargs):
        super(UserCreationFormExtended, self).__init__(*args, **kwargs)
        self.fields['email'].required = True

    def clean_email(self):
        """ensures unique email addresses, discounting stub accounts"""
        email = self.cleaned_data.get('email')
        if email and User.objects.filter(email=email).filter(userprofile__stub_account=False).count():
            raise forms.ValidationError(u'This email address is already in use.')
        return email

    class Meta:
        model = User<commit_msg>Removes the requirement for unique email addresses. Easier to remove than maintain, and I'm not sure why it even matters. Excised.<commit_after>from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.contrib.localflavor.us.forms import USStateField, USZipCodeField
from django.contrib.localflavor.us.us_states import STATE_CHOICES
from django.forms import ModelForm
from alert.userHandling.models import UserProfile


class ProfileForm(ModelForm):
    STATE_CHOICES = list(STATE_CHOICES)
    STATE_CHOICES.insert(0, ('', '---------'))
    state = USStateField(
        widget=forms.Select(
            choices=STATE_CHOICES,
            attrs={'class': 'span-5'}
        ),
        required=False,
    )
    zip_code = USZipCodeField(
        widget=forms.TextInput(
            attrs={'class': 'span-4'}
        ),
        required=False,
    )

    class Meta:
        model = UserProfile
        fields = (
            'employer',
            'address1',
            'address2',
            'city',
            'state',
            'zip_code',
            'wants_newsletter',
            'barmembership',
            'plaintext_preferred',
        )
        widgets = {
            'employer': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
            'barmembership': forms.SelectMultiple(
                attrs={'class': 'span-9',
                       'size': '8'}
            ),
            'address1': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
            'address2': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
            'city': forms.TextInput(
                attrs={'class': 'span-9'}
            ),
        }


class UserForm(ModelForm):
    email = forms.EmailField(
        required=True,
        widget=forms.TextInput(
            attrs={'class': 'span-9'}
        )
    )

    class Meta:
        model = User
        fields = (
            'first_name',
            'last_name',
            'email',
        )
        widgets = {
            'first_name': forms.TextInput(
                attrs={'class': 'span-4'}
            ),
            'last_name': forms.TextInput(
                attrs={'class': 'span-5'}
            ),
        }


class UserCreationFormExtended(UserCreationForm):
    def __init__(self, *args, **kwargs):
        super(UserCreationFormExtended, self).__init__(*args, **kwargs)
        self.fields['email'].required = True

    class Meta:
        model = User
{'fraction_non_alphanumeric': 0.12152166255723847, 'fraction_numerical': 0.005635787249031349, 'mean_word_length': 1.7567961165048545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4482488', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1548, 'n_words': 314}