From 9337238058c3066ab3f59bba1e9b64187e00ba74 Mon Sep 17 00:00:00 2001 From: Peter Holzer Date: Mon, 15 Aug 2016 16:42:04 +0200 Subject: [PATCH] updated checkEmailAddress to not be dependend on CMFDefault --- src/collective/contact/core/behaviors.py | 32 ++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/collective/contact/core/behaviors.py b/src/collective/contact/core/behaviors.py index 3a933578..b22b88f5 100644 --- a/src/collective/contact/core/behaviors.py +++ b/src/collective/contact/core/behaviors.py @@ -18,27 +18,39 @@ from plone.app.textfield import RichText from plone.app.dexterity.browser.types import TypeSchemaContext -from Products.CMFDefault.utils import checkEmailAddress -from Products.CMFDefault.exceptions import EmailAddressInvalid +# from Products.CMFDefault.utils import checkEmailAddress +# from Products.CMFDefault.exceptions import EmailAddressInvalid from collective.contact.core import _ from collective.contact.core.interfaces import IContactable from collective.contact.widget.schema import ContactChoice, ContactList from collective.contact.widget.source import ContactSourceBinder +# Taken from http://www.regular-expressions.info/email.html +_isemail = r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}" +_isemail = re.compile(_isemail).match + class InvalidEmailAddress(schema.ValidationError): """Exception for invalid address""" __doc__ = _(u"Invalid email address") -def validateEmail(value): - """Simple email validator""" - try: - checkEmailAddress(value) - except EmailAddressInvalid: - raise InvalidEmailAddress(value) - return True +# def validateEmail(value): +# super(Email, self)._validate(value) +# if _isemail(value): +# return + +# raise InvalidEmail(value) + + +# def validateEmail(value): +# """Simple email validator""" +# try: +# checkEmailAddress(value) +# except EmailAddressInvalid: +# raise InvalidEmailAddress(value) +# return True class InvalidPhone(schema.ValidationError): @@ -142,7 +154,7 @@ class IContactDetails(model.Schema): email = schema.TextLine( title=_(u"Email"), - constraint=validateEmail, + # constraint=validateEmail, required=False, )