本文整理汇总了Python中django.forms.EmailField.clean方法的典型用法代码示例。如果您正苦于以下问题:Python EmailField.clean方法的具体用法?Python EmailField.clean怎么用?Python EmailField.clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.EmailField
的用法示例。
在下文中一共展示了EmailField.clean方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_cc_list
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
def validate_cc_list(cc_list):
'''Validate each email in cc_list argument
This is called by ``notification_*`` methods internally.
No return value, and if any email in cc_list is not valid, ValidationError
will be raised.
'''
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)})
示例2: is_valid_email
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
def is_valid_email(address):
# FIXME In Django 1.2 we can use validators
field = EmailField()
try:
field.clean(address)
except ValidationError, e:
return False
示例3: test_emailfield_min_max_length
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
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" />')
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"):
f.clean("[email protected]")
self.assertEqual("[email protected]", f.clean("[email protected]"))
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 15 characters (it has 20).'"):
f.clean("[email protected]")
示例4: post
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
def post(self,request,*args,**kwargs):
email = request.POST['email']
ef = EmailField()
try:
ef.clean(email)
Candidate.objects.get(email=email)
except Candidate.DoesNotExist:
url = "%s?email=%s" % (reverse('home:reg'), email)
return HttpResponseRedirect(url)
except ValidationError:
messages.error(self.request, u"Email inválido")
else:
messages.info(self.request, u"O email %s já está cadastrado!" % email)
return super(HomeView, self).get(request,*args,**kwargs)
示例5: clean
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
def clean(self):
if 'username' in self.cleaned_data:
username = self.cleaned_data["username"]
else:
raise forms.ValidationError(_("Username and Password required"))
if 'password' in self.cleaned_data:
password = self.cleaned_data["password"]
else:
raise forms.ValidationError(_("Username and Password required"))
try:
# User can login via email address too
# Check whether the provided username is email
email_check = EmailField()
email = email_check.clean(username)
if self.request.site.is_core:
site_users = SiteUser.objects.filter(
email=email,
role=settings.SITE_ROLES['ADMIN'])
site_user = site_users[0]
else:
site_user = SiteUser.objects.get(email=email,
site_id=self.request.site.id)
unique_username = site_user.user.username
except SiteUser.DoesNotExist:
# Email does not exist in the current site
raise forms.ValidationError(_("Username or password incorrect"))
except forms.ValidationError:
# Not an email. Probably user is trying to login via username
try:
if self.request.site.is_core:
site_users = SiteUser.objects.filter(
username=username,
role=settings.SITE_ROLES['ADMIN'])
site_user = site_users[0]
else:
site_user = SiteUser.objects.get(
username=username,
site_id=self.request.site.id)
unique_username = site_user.user.username
except SiteUser.DoesNotExist:
#User name does not exist in current database
raise forms.ValidationError(
_("Username or password incorrect"))
user = authenticate(username=unique_username, password=password)
if user is not None:
if user.is_active:
login(self.request, user)
else:
raise forms.ValidationError(
_("This account is deactivated."))
else:
raise forms.ValidationError(
_("Username or password incorrect"))
示例6: test_emailfield_1
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
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('[email protected]', f.clean('[email protected]'))
with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('foo')
self.assertEqual(
'[email protected]\xe4\xf6\xfc\xdfabc.part.com',
f.clean('[email protected]äöüßabc.part.com')
)
示例7: test_emailfield_not_required
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
def test_emailfield_not_required(self):
f = EmailField(required=False)
self.assertEqual('', f.clean(''))
self.assertEqual('', f.clean(None))
self.assertEqual('[email protected]', f.clean('[email protected]'))
self.assertEqual('[email protected]', f.clean(' [email protected] \t \t '))
with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('foo')
示例8: clean
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
def clean(self):
"""called in `save()`
"""
emails = functions.split_list(self.preapproved_emails)
email_field = EmailField()
try:
map(lambda v: email_field.clean(v), emails)
except exceptions.ValidationError:
raise exceptions.ValidationError(
_('Please give a list of valid email addresses.')
)
self.preapproved_emails = ' ' + '\n'.join(emails) + ' '
domains = functions.split_list(self.preapproved_email_domains)
from askbot.forms import DomainNameField
domain_field = DomainNameField()
try:
map(lambda v: domain_field.clean(v), domains)
except exceptions.ValidationError:
raise exceptions.ValidationError(
_('Please give a list of valid email domain names.')
)
self.preapproved_email_domains = ' ' + '\n'.join(domains) + ' '
示例9: test_emailfield_strip_on_none_value
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
def test_emailfield_strip_on_none_value(self):
f = EmailField(required=False, empty_value=None)
self.assertIsNone(f.clean(None))
示例10: test_email_regexp_for_performance
# 需要导入模块: from django.forms import EmailField [as 别名]
# 或者: from django.forms.EmailField import clean [as 别名]
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.assertEqual(addr, f.clean(addr))