<commit_before>from django import forms

from slackin.conf import settings
from slackin.slack import Slack, SlackError


class SlackinInviteForm(forms.Form):
    email_address = forms.EmailField(required=True)

    def clean_email_address(self):
        email_address = self.cleaned_data['email_address']

        slack = Slack(token=settings.SLACKIN_TOKEN, subdomain=settings.SLACKIN_SUBDOMAIN)
        try:
            invitation = slack.invite_user(email_address=email_address,
                                           ultra_restricted=settings.SLACKIN_ULTRA_RESTRICTED_INVITES)
        except SlackError as err:
            raise forms.ValidationError(err)
        
        return email_address

    def __init__(self, *args, **kwargs):
        super(SlackinInviteForm, self).__init__(*args, **kwargs)<commit_msg>add comment explaining sending the Slack invite in clean_email_address() rather than save()<commit_after>from django import forms

from slackin.conf import settings
from slackin.slack import Slack, SlackError


class SlackinInviteForm(forms.Form):
    email_address = forms.EmailField(required=True)

    def clean_email_address(self):
        email_address = self.cleaned_data['email_address']

        slack = Slack(token=settings.SLACKIN_TOKEN, subdomain=settings.SLACKIN_SUBDOMAIN)
        try:
            # send the invite here (instead of save()) so that API errors (already invited, already
            # in team) can be presented as validation errors
            invitation = slack.invite_user(email_address=email_address,
                                           ultra_restricted=settings.SLACKIN_ULTRA_RESTRICTED_INVITES)
        except SlackError as err:
            raise forms.ValidationError(err)
        
        return email_address

    def __init__(self, *args, **kwargs):
        super(SlackinInviteForm, self).__init__(*args, **kwargs)
{'fraction_non_alphanumeric': 0.0740543420351625, 'fraction_numerical': 0.0, 'mean_word_length': 3.1004366812227073, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5239628', 'n_tokens_mistral': 538, 'n_tokens_neox': 520, 'n_words': 118}