当前位置: 首页>>代码示例>>Python>>正文


Python forms.EmailField类代码示例

本文整理汇总了Python中django.forms.EmailField的典型用法代码示例。如果您正苦于以下问题:Python EmailField类的具体用法?Python EmailField怎么用?Python EmailField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EmailField类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate_cc_list

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)})
开发者ID:Aaln1986,项目名称:Nitrate,代码行数:25,代码来源:testcase.py

示例2: is_valid_email

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
开发者ID:alexanderfefelov,项目名称:nav,代码行数:7,代码来源:__init__.py

示例3: clean

 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"))
开发者ID:centipair,项目名称:saas,代码行数:53,代码来源:forms.py

示例4: post

	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)
开发者ID:xvaldetaro,项目名称:caiubem,代码行数:15,代码来源:views.py

示例5: test_emailfield_1

 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')
     )
开发者ID:ArcTanSusan,项目名称:django,代码行数:14,代码来源:test_emailfield.py

示例6: test_emailfield_not_required

 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')
开发者ID:ArcTanSusan,项目名称:django,代码行数:8,代码来源:test_emailfield.py

示例7: test_emailfield_min_max_length

 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]")
开发者ID:ydnaandy123,项目名称:DashCam_WebGL,代码行数:8,代码来源:test_emailfield.py

示例8: clean

    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) + ' '
开发者ID:Antonytm,项目名称:askbot-devel,代码行数:23,代码来源:user.py

示例9: test_emailfield_strip_on_none_value

 def test_emailfield_strip_on_none_value(self):
     f = EmailField(required=False, empty_value=None)
     self.assertIsNone(f.clean(None))
开发者ID:ArcTanSusan,项目名称:django,代码行数:3,代码来源:test_emailfield.py

示例10: test_email_regexp_for_performance

 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))
开发者ID:ArcTanSusan,项目名称:django,代码行数:6,代码来源:test_emailfield.py


注:本文中的django.forms.EmailField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。