def test__to_python(self):
     f = MultiEmailFormField()
     # Empty values
     for val in ['', None]:
         self.assertEquals([], f.to_python(val))
     # One line correct value
     val = '  [email protected]    '
     self.assertEquals(['*****@*****.**'], f.to_python(val))
     # Multi lines correct values (test of #0010614)
     val = '[email protected]\[email protected]\r\[email protected]'
     self.assertEquals(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                       f.to_python(val))
 def test__to_python(self):
     f = MultiEmailFormField()
     # Empty values
     for val in ['', None]:
         self.assertEquals([], f.to_python(val))
     # One line correct value
     val = '  [email protected]    '
     self.assertEquals(['*****@*****.**'], f.to_python(val))
     # Multi lines correct values (test of #0010614)
     val = '[email protected],\[email protected],\r\[email protected],,'
     self.assertEquals(['*****@*****.**', '*****@*****.**', '*****@*****.**'],
                       f.to_python(val))
Beispiel #3
0
class SponsorDetailsForm(forms.ModelForm):
    contact_emails = MultiEmailField(
        help_text=_(u"Please enter one email address per line."))

    class Meta:
        model = Sponsor
        fields = [
            "name",
            "contact_name",
            "contact_emails",
            "contact_phone",
            "contact_address",
            "external_url",
            "display_url",
            "twitter_username",
            "web_description",
            "web_logo",
        ]
        widgets = {
            'web_description':
            forms.widgets.Textarea(attrs={
                'cols': 40,
                'rows': 5
            }),
        }
 def test__validate(self):
     f = MultiEmailFormField(required=True)
     # Empty value
     val = []
     self.assertRaises(ValidationError, f.validate, val)
     # Incorrect value
     val = ['not-an-email.com']
     self.assertRaises(ValidationError, f.validate, val)
     # An incorrect value with correct values
     val = ['*****@*****.**', 'not-an-email.com', '*****@*****.**']
     self.assertRaises(ValidationError, f.validate, val)
     # Should not happen (to_python do the strip)
     val = ['  [email protected]    ']
     self.assertRaises(ValidationError, f.validate, val)
     # Correct value
     val = ['*****@*****.**']
     f.validate(val)
 def test__validate(self):
     f = MultiEmailFormField(required=True)
     # Empty value
     val = []
     self.assertRaises(ValidationError, f.validate, val)
     # Incorrect value
     val = ['not-an-email.com']
     self.assertRaises(ValidationError, f.validate, val)
     # An incorrect value with correct values
     val = ['*****@*****.**', 'not-an-email.com', '*****@*****.**']
     self.assertRaises(ValidationError, f.validate, val)
     # Should not happen (to_python do the strip)
     val = ['  [email protected]    ']
     self.assertRaises(ValidationError, f.validate, val)
     # Correct value
     val = ['*****@*****.**']
     f.validate(val)
Beispiel #6
0
class SponsorDetailsForm(forms.ModelForm):
    contact_emails = MultiEmailField(
        help_text=_(u"Please enter one email address per line."))

    class Meta:
        model = Sponsor
        fields = [
            "name",
            "contact_name",
            "contact_emails",
            "contact_phone",
            "contact_address",
            "external_url",
            "display_url",
            "twitter_username",
            "web_description",
            "web_logo",
            "print_logo",
        ]
        widgets = {
            'web_description':
            forms.widgets.Textarea(attrs={
                'cols': 40,
                'rows': 5
            }),
        }

    def clean_web_logo(self):
        image_file = self.cleaned_data.get("web_logo")
        if image_file:
            if not image_file.name.split('.')[-1].lower() in WEB_LOGO_TYPES:
                raise forms.ValidationError(
                    "Your file extension was not recognized, please submit "
                    "one of: {}".format(', '.join(WEB_LOGO_TYPES)))
            w, h = get_image_dimensions(image_file)
            if w < 256 and h < 256:
                raise forms.ValidationError(
                    "Smallest dimension must be no less than 256px, "
                    "submitted image had dimensions {}x{}".format(w, h))
        else:
            raise forms.ValidationError("You must supply a web logo file")
        return image_file

    def clean_print_logo(self):
        image_file = self.cleaned_data.get("print_logo")
        if image_file:
            if not image_file.name.split('.')[-1].lower() in PRINT_LOGO_TYPES:
                raise forms.ValidationError(
                    "Your file extension was not recognized, please submit "
                    "one of: {}".format(', '.join(PRINT_LOGO_TYPES)))
        return image_file
Beispiel #7
0
class EmailForm(forms.Form):
    DESIGNATION_CHOICES = [
        ('Student', 'Student'),
        ('Teacher', 'Teacher'),
        ('Lawyer', 'Lawyer'),
        ('Business', 'Business'),
    ]

    fullname = forms.CharField(label='Your Name',
                               max_length=50,
                               widget=forms.TextInput())
    company = forms.CharField(label='Company Name',
                              max_length=50,
                              required=False,
                              widget=forms.TextInput())
    designation = forms.ChoiceField(required=False,
                                    choices=DESIGNATION_CHOICES)
    email_input = forms.EmailField(label="Input Email",
                                   required=False,
                                   max_length=60,
                                   widget=forms.TextInput())
    # email = forms.CharField(label='Recipient', max_length=100, widget=forms.TextInput())
    email = MultiEmailField(label='Recipient')
    subject = forms.CharField(max_length=255, widget=forms.TextInput())
    message = forms.CharField(max_length=500, widget=forms.Textarea())
    attachment = forms.FileField(
        label='',
        required=False,
        widget=forms.ClearableFileInput(attrs={'multiple': True}))

    def __init__(self, *args, **kwargs):
        super(EmailForm, self).__init__(*args, **kwargs)
        #Email-input
        self.fields['email_input'].widget.attrs['id'] = 'email_input'
        self.fields['email_input'].widget.attrs[
            'onkeypress'] = 'eventListener(event)'
        self.fields['email_input'].widget.attrs[
            'onkeyup'] = 'eventListener2(event)'

        # MultiEmailField
        self.fields['email'].widget.attrs['readonly'] = 'readonly'

        # message
        self.fields['message'].widget.attrs[
            'placeholder'] = 'Write something.....'

        # File-attachment
        self.fields['attachment'].widget.attrs[
            'style'] = 'background-color: red;'  # not displaying the main file-upload btn, hide it on-page
        self.fields['attachment'].widget.attrs['id'] = 'upfile'
        self.fields['attachment'].widget.attrs['onchange'] = 'sub(this)'
Beispiel #8
0
class InstitutionMembersInviteForm(forms.Form):
    member_emails = MultiEmailField(required=True)

    def __init__(self, institution=None, *args, **kwargs):
        super(InstitutionMembersInviteForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_action = 'institution_invite_members'
        self.helper.form_method = 'post'
        self.helper.form_tag = False
        self.institution = institution

    def clean(self):
        if not self.institution.is_subscription_active():
            raise ValidationError("The subscription is not active and you can't invite members")
        return self.cleaned_data

    def invite_members(self, request):
        adapter = get_adapter()
        members = []
        for email in self.cleaned_data.get('member_emails'):
            try:
                user = User.objects.get(email=email)
                if not user.institution:
                    user.institution = self.institution
                    user.save()
                    members.append(user)
            except ObjectDoesNotExist:
                user = adapter.new_user(request)
                user.email = email
                user.institution = self.institution
                user.set_unusable_password()
                adapter.populate_username(request, user)
                user.save()
                setup_user_email(request, user, [])
                members.append(user)
            send_email_confirmation_task.delay(user_id=user.id, signup=True)
            storage = messages.get_messages(request)
            storage.used = True
            messages.success(request, 'Members successfully invited')
        return members

    def raise_duplicate_email_error(self):
        # don't raise errors, used for resending invites to users
        pass
Beispiel #9
0
class MessageForm(forms.ModelForm):
    receivers = forms.ModelMultipleChoiceField(User.objects, required=False,)
    title = forms.CharField(required=False)
    text = forms.Textarea()
    send_date = forms.DateTimeField(required=False, widget=DateTimeInput,
                                    input_formats=["%Y-%m-%dT%H:%M", "%Y-%m-%d %H:%M"])
    emails = MultiEmailField(required=False)
    # file_field = forms.FileField(required=False, widget=forms.ClearableFileInput(attrs={'multiple': True}))

    def __init__(self, *args, **kwargs):
        super(MessageForm, self).__init__(*args, **kwargs)
        for visible in self.visible_fields():
            visible.field.widget.attrs['class'] = 'form-control'
        self.fields["emails"].widget.attrs['rows'] = "2"
        self.fields["text"].widget.attrs['rows'] = "2"

    class Meta:
        model = Message
        fields = ['receivers', 'emails', 'title', 'text', 'send_date']

    def clean_send_date(self):
        date = self.cleaned_data.get('send_date')
        cd = self.cleaned_data
        if date:
            if date < timezone.now():
                raise forms.ValidationError(_('Invalid datetime: %(value)s'),
                        params={'value': date},
                    )
        return date

    def clean(self):
        receivers = self.cleaned_data.get('receivers')
        emails = self.cleaned_data.get('emails')
        if not receivers and not emails:
            raise forms.ValidationError(_('Error: No receivers or emails'))
        return self.cleaned_data
Beispiel #10
0
class SendMessageForm(forms.Form):
    emails = MultiEmailField(label='נמענים')
class AddEmailForm(forms.Form):
    """
    Configuration form that allows the user to input desired notification
    recipients.
    """
    emails = MultiEmailField(widget=MultiEmailWidget())
Beispiel #12
0
class SendMessageForm(forms.Form):
    emails = MultiEmailField()