Python django.forms.EmailField() Examples
The following are 30
code examples of django.forms.EmailField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms
, or try the search function
.
Example #1
Source File: forms.py From connect with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) super(UpdateEmailForm, self).__init__(*args, **kwargs) self.fields['email'] = forms.EmailField( initial=self.user.email, widget=forms.EmailInput(attrs={ 'placeholder': _('Email') }), error_messages={ 'required': _('Please enter your new email address.'), 'invalid': _('Please enter a valid email address.') }) self.fields['password'] = forms.CharField( widget=forms.PasswordInput(attrs={ 'placeholder': _('Password') }), error_messages={ 'required': _('Please enter your password.'), })
Example #2
Source File: forms_json.py From starthinker with Apache License 2.0 | 6 votes |
def get_field_kind(field): if field['kind'] == 'string': return forms.CharField(max_length=255, required=False) elif field['kind'] == 'email': return forms.EmailField(max_length=255, required=False) elif field['kind'] == 'integer': return forms.IntegerField(required=False) elif field['kind'] == 'boolean': return forms.BooleanField(required=False) elif field['kind'] == 'text': return forms.CharField(widget=forms.Textarea(), required=False) elif field['kind'] == 'choice': return forms.ChoiceField(choices=map(lambda c: (c,c), field['choices'])) elif field['kind'] == 'timezones': return TimezoneField() elif field['kind'] == 'authentication': return SwitchField('user', 'service', required=True) elif field['kind'] == 'json': return JsonField(required=False) elif field['kind'] == 'integer_list': return CommaSeparatedIntegerField(required=False) elif field['kind'] == 'string_list': return CommaSeparatedCharField(required=False) else: return forms.CharField(max_length=255, required=False)
Example #3
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_min_max_length(self): f = EmailField(min_length=10, max_length=15) self.assertWidgetRendersTo( f, '<input id="id_f" type="email" name="f" maxlength="15" minlength="10" required>', ) with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"): f.clean('a@foo.com') self.assertEqual('alf@foo.com', f.clean('alf@foo.com')) with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 15 characters (it has 20).'"): f.clean('alf123456788@foo.com')
Example #4
Source File: __init__.py From python2017 with MIT License | 5 votes |
def formfield(self, **kwargs): # As with CharField, this will cause email validation to be performed # twice. defaults = { 'form_class': forms.EmailField, } defaults.update(kwargs) return super(EmailField, self).formfield(**defaults)
Example #5
Source File: test_converter.py From graphene-django with MIT License | 5 votes |
def test_should_email_convert_string(): assert_conversion(forms.EmailField, String)
Example #6
Source File: djangoforms.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def get_form_field(self, **kwargs): """Return a Django form field appropriate for a User property. This defaults to a forms.EmailField instance, except if auto_current_user or auto_current_user_add is set, in which case None is returned, as such 'auto' fields should not be rendered as part of the form. """ if self.auto_current_user or self.auto_current_user_add: return None defaults = {'form_class': forms.EmailField} defaults.update(kwargs) return super(UserProperty, self).get_form_field(**defaults)
Example #7
Source File: forms.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def add_fields(self, form, index): form.fields["email"] = EmailField(label=email_field_label)
Example #8
Source File: forms.py From logtacts with MIT License | 5 votes |
def __init__(self, *args, **kwargs): document_items = None self.user = kwargs.pop('user', None) if kwargs.get('data'): document_items = dict((key, value) for key, value in kwargs.get('data').items() if key.startswith('document')) self.book = kwargs.pop('book') tag_choices = kwargs.pop('tag_choices') super(ContactForm, self).__init__(*args, **kwargs) choices = Tag.objects.filter(book=self.book).values_list('id', 'tag') self.fields['tags'].choices = tag_choices self.fields['deleted_fields'] = forms.CharField(required=False) if document_items: for item in document_items: parts = item.split('_') field_category = parts[1] if len(parts) == 4: if parts[3] == 'pref': self.fields[item] = forms.BooleanField() if parts[3] == 'label': self.fields[item] = forms.CharField(max_length=255) else: if field_category == contact_constants.FIELD_TYPE_EMAIL: self.fields[item] = forms.EmailField(max_length=255) if field_category == contact_constants.FIELD_TYPE_URL: self.fields[item] = forms.URLField(max_length=255) if field_category == contact_constants.FIELD_TYPE_DATE: self.fields[item] = forms.DateField() else: self.fields[item] = forms.CharField()
Example #9
Source File: blocks.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_field_class(self, struct_value): text_format = struct_value['format'] if text_format == 'url': return forms.URLField if text_format == 'email': return forms.EmailField return super().get_field_class(struct_value)
Example #10
Source File: testcase.py From Kiwi with GNU General Public License v2.0 | 5 votes |
def _validate_cc_list(cc_list): """ Validate each email address given in argument. Called by notification RPC methods. :param cc_list: List of email addresses :type cc_list: list :raises TypeError or ValidationError: if addresses are not valid. """ if not isinstance(cc_list, list): raise TypeError('cc_list should be a list object.') field = EmailField(required=True) invalid_emails = [] for item in cc_list: try: field.clean(item) except ValidationError: invalid_emails.append(item) if invalid_emails: raise ValidationError( field.error_messages['invalid'] % { 'value': ', '.join(invalid_emails)})
Example #11
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_assert_field_output(self): error_invalid = ['Enter a valid email address.'] self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid}) with self.assertRaises(AssertionError): self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid + ['Another error']}) with self.assertRaises(AssertionError): self.assertFieldOutput(EmailField, {'a@a.com': 'Wrong output'}, {'aaa': error_invalid}) with self.assertRaises(AssertionError): self.assertFieldOutput( EmailField, {'a@a.com': 'a@a.com'}, {'aaa': ['Come on, gimme some well formatted data, dude.']} )
Example #12
Source File: test_combofield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_combofield_1(self): f = ComboField(fields=[CharField(max_length=20), EmailField()]) self.assertEqual('test@example.com', f.clean('test@example.com')) with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"): f.clean('longemailaddress@example.com') with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"): f.clean('not an email') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean('') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean(None)
Example #13
Source File: test_combofield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_combofield_2(self): f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False) self.assertEqual('test@example.com', f.clean('test@example.com')) with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"): f.clean('longemailaddress@example.com') with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"): f.clean('not an email') self.assertEqual('', f.clean('')) self.assertEqual('', f.clean(None))
Example #14
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_1(self): f = EmailField() self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" required>') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean('') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean(None) self.assertEqual('person@example.com', f.clean('person@example.com')) with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"): f.clean('foo') self.assertEqual( 'local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com', f.clean('local@domain.with.idn.xyzäöüßabc.part.com') )
Example #15
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_email_regexp_for_performance(self): f = EmailField() # Check for runaway regex security problem. This will take a long time # if the security fix isn't in place. addr = 'viewx3dtextx26qx3d@yahoo.comx26latlngx3d15854521645943074058' self.assertEqual(addr, f.clean(addr))
Example #16
Source File: __init__.py From python2017 with MIT License | 5 votes |
def deconstruct(self): name, path, args, kwargs = super(EmailField, self).deconstruct() # We do not exclude max_length if it matches default as we want to change # the default in future. return name, path, args, kwargs
Example #17
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_strip_on_none_value(self): f = EmailField(required=False, empty_value=None) self.assertIsNone(f.clean(None))
Example #18
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_unable_to_set_strip_kwarg(self): msg = "__init__() got multiple values for keyword argument 'strip'" with self.assertRaisesMessage(TypeError, msg): EmailField(strip=False)
Example #19
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_assert_field_output(self): error_invalid = ['Enter a valid email address.'] self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid}) with self.assertRaises(AssertionError): self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid + ['Another error']}) with self.assertRaises(AssertionError): self.assertFieldOutput(EmailField, {'a@a.com': 'Wrong output'}, {'aaa': error_invalid}) with self.assertRaises(AssertionError): self.assertFieldOutput( EmailField, {'a@a.com': 'a@a.com'}, {'aaa': ['Come on, gimme some well formatted data, dude.']} )
Example #20
Source File: test_combofield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_combofield_1(self): f = ComboField(fields=[CharField(max_length=20), EmailField()]) self.assertEqual('test@example.com', f.clean('test@example.com')) with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"): f.clean('longemailaddress@example.com') with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"): f.clean('not an email') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean('') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean(None)
Example #21
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_1(self): f = EmailField() self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" required>') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean('') with self.assertRaisesMessage(ValidationError, "'This field is required.'"): f.clean(None) self.assertEqual('person@example.com', f.clean('person@example.com')) with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"): f.clean('foo') self.assertEqual( 'local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com', f.clean('local@domain.with.idn.xyzäöüßabc.part.com') )
Example #22
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_email_regexp_for_performance(self): f = EmailField() # Check for runaway regex security problem. This will take a long time # if the security fix isn't in place. addr = 'viewx3dtextx26qx3d@yahoo.comx26latlngx3d15854521645943074058' self.assertEqual(addr, f.clean(addr))
Example #23
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_not_required(self): f = EmailField(required=False) self.assertEqual('', f.clean('')) self.assertEqual('', f.clean(None)) self.assertEqual('person@example.com', f.clean('person@example.com')) self.assertEqual('example@example.com', f.clean(' example@example.com \t \t ')) with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"): f.clean('foo')
Example #24
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_min_max_length(self): f = EmailField(min_length=10, max_length=15) self.assertWidgetRendersTo( f, '<input id="id_f" type="email" name="f" maxlength="15" minlength="10" required>', ) with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"): f.clean('a@foo.com') self.assertEqual('alf@foo.com', f.clean('alf@foo.com')) with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 15 characters (it has 20).'"): f.clean('alf123456788@foo.com')
Example #25
Source File: test_emailfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_emailfield_strip_on_none_value(self): f = EmailField(required=False, empty_value=None) self.assertIsNone(f.clean(None))
Example #26
Source File: fields.py From esdc-ce with Apache License 2.0 | 5 votes |
def from_native(self, value): ret = super(EmailField, self).from_native(value) if ret is None: return None return ret.strip()
Example #27
Source File: forms.py From djangocms-forms with BSD 3-Clause "New" or "Revised" License | 5 votes |
def prepare_email(self, field): field_attrs = field.build_field_attrs() widget_attrs = field.build_widget_attrs(extra_attrs={'autocomplete': 'email'}) field_attrs.update({ 'widget': forms.EmailInput(attrs=widget_attrs), }) return forms.EmailField(**field_attrs)
Example #28
Source File: views.py From shortweb with MIT License | 5 votes |
def validate_url(url): protocols=[ 'http://', 'https://', ] flag=0 url_form_field = URLField() email_field = EmailField() try : email_field.clean(url) except ValidationError: if url!='': for protocol in protocols: n=len(protocol) if url[0:n]==protocol: flag=1 break if flag==0: flag1=1 for protocol in protocols: new_url = protocol+url try: new_url == url_form_field.clean(new_url) except ValidationError: flag1=0 else: url=new_url break if flag1==1: return True,url return False,url return True,url return False,url else: return False,url
Example #29
Source File: __init__.py From python2017 with MIT License | 5 votes |
def __init__(self, *args, **kwargs): # max_length=254 to be compliant with RFCs 3696 and 5321 kwargs['max_length'] = kwargs.get('max_length', 254) super(EmailField, self).__init__(*args, **kwargs)
Example #30
Source File: text.py From coursys with GNU General Public License v3.0 | 5 votes |
def make_entry_field(self, fieldsubmission=None): c = forms.EmailField(required=self.config['required'], label=self.config['label'], help_text=self.config['help_text']) if fieldsubmission: c.initial = fieldsubmission.data['info'] return c