<commit_before>"""Provides the forms for the first login wizard."""

import re

from django import forms
from django.conf import settings
from django.contrib.auth.models import User

from apps.managers.player_mgr.models import Profile


class FacebookForm(forms.Form):
    """Form about can post to facebook."""
    can_post = forms.BooleanField(
        required=False,
        initial=True,
        label="%s can post to my Facebook feed (at most 2 posts per day)" %
              (settings.CHALLENGE.competition_name)
    )


class ReferralForm(forms.Form):
    """Form for referral bonus."""
    referrer_email = forms.EmailField(
        required=False,
        label='Referrer Email (Optional)'
    )

    def __init__(self, *args, **kwargs):
        """
        Override for init to take a user argument.
        """
        self.user = kwargs.pop('user', None)
        super(ReferralForm, self).__init__(*args, **kwargs)

    def clean(self):
        """Check to make sure the user is not submitting their own email."""
        cleaned_data = self.cleaned_data
        if self.user.email == cleaned_data.get('referrer_email'):
            raise forms.ValidationError(
                "Please use another user's email address, not your own.")

        return cleaned_data

    def clean_referrer_email(self):
        """Check to make sure the referring user is part of the competition."""
        email = self.cleaned_data['referrer_email']
        if email:
            # Check if user is in the system.
            try:
                User.objects.get(email=email, is_staff=False)
            except User.DoesNotExist:
                raise forms.ValidationError(
                    "Sorry, but that user is not a part of the competition.")
        return email


class ProfileForm(forms.Form):
    """Form for modified profile info"""
    display_name = forms.CharField(
        max_length=20,
        help_text="This name will be shown in scoreboards and on your " \
                  "profile instead of your UH username."
    )
    facebook_photo = forms.URLField(widget=forms.HiddenInput, required=False)
    use_fb_photo = forms.BooleanField(required=False)
    avatar = forms.ImageField(required=False)

    def __init__(self, *args, **kwargs):
        """Allow init to take a user argument."""
        self.user = kwargs.pop('user', None)
        super(ProfileForm, self).__init__(*args, **kwargs)

    def clean_display_name(self):
        """Verify display name: trim whitespace, require non-empty, no duplicates."""
        name = self.cleaned_data['display_name'].strip()
        # Remove extra whitespace from the name.
        spaces = re.compile(r'\s+')
        name = spaces.sub(' ', name)

        # Check for name that is just whitespace.
        if name == '':
            raise forms.ValidationError('This field is required')

        # Check for duplicate name
        if Profile.objects.exclude(user=self.user).filter(
            name=name).count() > 0:
            raise forms.ValidationError(
                "%s is taken.  Please use another name.")

        return name
<commit_msg>added error message for entering an admin email address.<commit_after>"""Provides the forms for the first login wizard."""

import re

from django import forms
from django.conf import settings
from django.contrib.auth.models import User

from apps.managers.player_mgr.models import Profile


class FacebookForm(forms.Form):
    """Form about can post to facebook."""
    can_post = forms.BooleanField(
        required=False,
        initial=True,
        label="%s can post to my Facebook feed (at most 2 posts per day)" %
              (settings.CHALLENGE.competition_name)
    )


class ReferralForm(forms.Form):
    """Form for referral bonus."""
    referrer_email = forms.EmailField(
        required=False,
        label='Referrer Email (Optional)'
    )

    def __init__(self, *args, **kwargs):
        """
        Override for init to take a user argument.
        """
        self.user = kwargs.pop('user', None)
        super(ReferralForm, self).__init__(*args, **kwargs)

    def clean(self):
        """Check to make sure the user is not submitting their own email."""
        cleaned_data = self.cleaned_data
        if self.user.email == cleaned_data.get('referrer_email'):
            raise forms.ValidationError(
                "Please use another user's email address, not your own.")

        return cleaned_data

    def clean_referrer_email(self):
        """Check to make sure the referring user is part of the competition."""
        email = self.cleaned_data['referrer_email']
        if email:
            # Check if referer is staff.
            try:
                User.objects.get(email=email, is_staff=True)
                raise forms.ValidationError(
                    "Sorry, but admins are invalid referers.")
            except User.DoesNotExist:
            # Check to see if they exist as players.
                try:
                    User.objects.get(email=email, is_staff=False)
                except User.DoesNotExist:
                    raise forms.ValidationError(
                        "Sorry, but that user is not a part of the competition.")
        return email


class ProfileForm(forms.Form):
    """Form for modified profile info"""
    display_name = forms.CharField(
        max_length=20,
        help_text="This name will be shown in scoreboards and on your " \
                  "profile instead of your UH username."
    )
    facebook_photo = forms.URLField(widget=forms.HiddenInput, required=False)
    use_fb_photo = forms.BooleanField(required=False)
    avatar = forms.ImageField(required=False)

    def __init__(self, *args, **kwargs):
        """Allow init to take a user argument."""
        self.user = kwargs.pop('user', None)
        super(ProfileForm, self).__init__(*args, **kwargs)

    def clean_display_name(self):
        """Verify display name: trim whitespace, require non-empty, no duplicates."""
        name = self.cleaned_data['display_name'].strip()
        # Remove extra whitespace from the name.
        spaces = re.compile(r'\s+')
        name = spaces.sub(' ', name)

        # Check for name that is just whitespace.
        if name == '':
            raise forms.ValidationError('This field is required')

        # Check for duplicate name
        if Profile.objects.exclude(user=self.user).filter(
            name=name).count() > 0:
            raise forms.ValidationError(
                "%s is taken.  Please use another name.")

        return name

{'fraction_non_alphanumeric': 0.09977186311787073, 'fraction_numerical': 0.0012167300380228137, 'mean_word_length': 2.341463414634146, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2252651', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1730, 'n_words': 559}