Here are the examples of the python api django.forms.EmailField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
18 Examples
3
View Complete Implementation : forms.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def __init__(self, *args, **kwargs):
super(UserCreationFormExtended, self).__init__(*args, **kwargs)
self.fields['email'] = forms.EmailField(
label=_("E-mail"),
max_length=75,
)
3
View Complete Implementation : __init__.py
Copyright GNU General Public License v2.0
Author : blackye
Copyright GNU General Public License v2.0
Author : blackye
def formfield(self, **kwargs):
# As with CharField, this will cause email validation to be performed
# twice.
defaults = {
'form_clast': forms.EmailField,
}
defaults.update(kwargs)
return super(EmailField, self).formfield(**defaults)
3
View Complete Implementation : test_fields.py
Copyright MIT License
Author : labd
Copyright MIT License
Author : labd
def test_email_field(self):
data = self.get_form_field_data('email')
cls = wsf_fields.EmailField()
field = cls.get_formfield(data)
self.astertIsInstance(field, forms.EmailField)
self.astertIsInstance(field.widget, forms.widgets.EmailInput)
self.astertEqual(field.label, data['label'])
self.astertEqual(field.required, data['required'])
self.astertEqual(field.help_text, data['help_text'])
self.astertEqual(field.initial, data['default_value'])
3
View Complete Implementation : test_combofield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_combofield_1(self):
f = ComboField(fields=[CharField(max_length=20), EmailField()])
self.astertEqual('[email protected]', f.clean('[email protected]'))
with self.astertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"):
f.clean('[email protected]')
with self.astertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('not an email')
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)
3
View Complete Implementation : test_combofield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_combofield_2(self):
f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
self.astertEqual('[email protected]', f.clean('[email protected]'))
with self.astertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"):
f.clean('[email protected]')
with self.astertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('not an email')
self.astertEqual('', f.clean(''))
self.astertEqual('', f.clean(None))
3
View Complete Implementation : test_emailfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_emailfield_1(self):
f = EmailField()
self.astertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" required>')
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)
self.astertEqual('[email protected]', f.clean('[email protected]'))
with self.astertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('foo')
self.astertEqual(
'[email protected]\xe4\xf6\xfc\xdfabc.part.com',
f.clean('[email protected]äöüßabc.part.com')
)
3
View Complete Implementation : test_emailfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
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 = '[email protected]'
self.astertEqual(addr, f.clean(addr))
3
View Complete Implementation : test_emailfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_emailfield_not_required(self):
f = EmailField(required=False)
self.astertEqual('', f.clean(''))
self.astertEqual('', f.clean(None))
self.astertEqual('[email protected]', f.clean('[email protected]'))
self.astertEqual('[email protected]', f.clean(' [email protected] \t \t '))
with self.astertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('foo')
3
View Complete Implementation : test_emailfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_emailfield_min_max_length(self):
f = EmailField(min_length=10, max_length=15)
self.astertWidgetRendersTo(
f,
'<input id="id_f" type="email" name="f" maxlength="15" minlength="10" required>',
)
with self.astertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"):
f.clean('[email protected]')
self.astertEqual('[email protected]', f.clean('[email protected]'))
with self.astertRaisesMessage(ValidationError, "'Ensure this value has at most 15 characters (it has 20).'"):
f.clean('[email protected]')
3
View Complete Implementation : test_error_messages.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_emailfield(self):
e = {
'required': 'REQUIRED',
'invalid': 'INVALID',
'min_length': 'LENGTH %(show_value)s, MIN LENGTH %(limit_value)s',
'max_length': 'LENGTH %(show_value)s, MAX LENGTH %(limit_value)s',
}
f = EmailField(min_length=8, max_length=10, error_messages=e)
self.astertFormErrors(['REQUIRED'], f.clean, '')
self.astertFormErrors(['INVALID'], f.clean, 'abcdefgh')
self.astertFormErrors(['LENGTH 7, MIN LENGTH 8'], f.clean, '[email protected]')
self.astertFormErrors(['LENGTH 11, MAX LENGTH 10'], f.clean, '[email protected]')
3
View Complete Implementation : test_forms.py
Copyright Apache License 2.0
Author : ooknosi
Copyright Apache License 2.0
Author : ooknosi
def test_MaterialForm_materializes_EmailField(self):
"""django.forms.widgets.EmailInput should be converted to
material_widgets.widgets.MaterialEmailInput.
"""
clast EmailInputForm(MaterialForm):
email_input = forms.EmailField()
form = EmailInputForm()
self.astertEqual(
type(form.fields['email_input'].widget),
widgets.MaterialEmailInput,
)
0
View Complete Implementation : test_converter.py
Copyright MIT License
Author : graphql-python
Copyright MIT License
Author : graphql-python
def test_should_email_convert_string():
astert_conversion(forms.EmailField, String)
0
View Complete Implementation : testcase.py
Copyright GNU General Public License v2.0
Author : kiwitcms
Copyright GNU General Public License v2.0
Author : kiwitcms
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
:return: None
: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)})
0
View Complete Implementation : views.py
Copyright GNU Lesser General Public License v3.0
Author : littlemo
Copyright GNU Lesser General Public License v3.0
Author : littlemo
def post(self, request, format=None):
'''
用例::
{
"email": "[email protected]"
}
'''
email = request.data.get('email', None)
log.info('email: {}'.format(email))
if not email:
return Response(
_('email 字段为空'), status=status.HTTP_400_BAD_REQUEST)
f = forms.EmailField()
try:
email = f.clean(email)
except ValidationError as e:
return Response(
_('Email 值错误:{}'.format(', '.join(e))),
status=status.HTTP_400_BAD_REQUEST)
try:
invite = Invitation.create(email, inviter=self.request.user)
invite.save()
invite.send_invitation(self.request)
except Exception as e:
return Response(e, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(
_('已发送注册邀请邮件到【{email}】').format(email=email),
status=status.HTTP_200_OK)
0
View Complete Implementation : views.py
Copyright GNU Lesser General Public License v3.0
Author : littlemo
Copyright GNU Lesser General Public License v3.0
Author : littlemo
def post(self, request, format=None):
'''
用例::
{
"device_addr": "[email protected]"
}
'''
um_device_addr = request.data.get('device_addr', None)
log.info('um_device_addr: {}'.format(um_device_addr))
f = forms.EmailField(required=False)
try:
um_device_addr = f.clean(um_device_addr)
except ValidationError as e:
return Response({
'device_addr': {
'rc': False,
'msg': _('Email 值错误:{}').format(', '.join(e))
},
}, status=status.HTTP_200_OK)
try:
um, created = UserMeta.objects.get_or_create(
user=request.user,
name=UserMeta.MOEAR_DEVICE_ADDR,
defaults={
'value': um_device_addr,
})
if not created:
um.value = um_device_addr
um.save()
except Exception as e:
return Response(e, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response({
'device_addr': {
'rc': True,
}
}, status=status.HTTP_200_OK)
0
View Complete Implementation : views.py
Copyright MIT License
Author : modihere
Copyright MIT License
Author : modihere
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
0
View Complete Implementation : test_emailfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_emailfield_strip_on_none_value(self):
f = EmailField(required=False, empty_value=None)
self.astertIsNone(f.clean(None))
0
View Complete Implementation : test_emailfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_emailfield_unable_to_set_strip_kwarg(self):
msg = "__init__() got multiple values for keyword argument 'strip'"
with self.astertRaisesMessage(TypeError, msg):
EmailField(strip=False)