def validate_user_name(value): site = getSite() pc = getToolByName(site, 'portal_personcatalog') results = pc.searchResults(object_provides=IPerson.__identifier__, id=value) if len(results) > 0: return _(u'There is a person already assigned to this username')
def validate_telephone(value): ''' Validate a phone number >>> validate_telephone('+551138982121') True >>> validate_telephone('+55(11)3898.2121') True >>> validate_telephone('+55-11-3898-2121') True >>> try: ... validate_telephone('+55-11-3898-SIMP') ... except Invalid: ... print 'Invalid phone' Invalid phone >>> try: ... validate_telephone('11-3898-2121') ... except Invalid: ... print 'Invalid phone' Invalid phone ''' valid = digits + '+' value = ''.join([c for c in value if c in valid]) pattern = re.compile('\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[854321]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{7,14}$') if re.match(pattern, value): return True else: raise Invalid(_(u"The informed phone number is invalid."))
def validate_email(value): ''' Validate email using Products.validation >>> validate_email('*****@*****.**') == 1 True >>> validate_email('*****@*****.**') == 1 True >>> validate_email('*****@*****.**') == 1 True >>> validate_email('*****@*****.**') == 1 True >>> try: ... validate_email('@bar.com') ... except Invalid: ... print 'Invalid email' Invalid email ''' v = validation.validatorFor('isEmail') if v(str(value)) == 1: return True else: raise Invalid(_(u"The informed email is invalid."))
def validate_telephones(data): ''' Validate provided telephones ''' telephones = data.telephones if telephones: for line in telephones: phone = line.get('data', '') if phone and not validate_telephone(phone): return InvalidInformation(_(u'Invalid Phone Number'))
def validate_emails(data): ''' Validate provided emails ''' emails = data.emails if emails: for line in emails: email = line.get('data', '') if email and not validate_email(email): return InvalidInformation(_(u'Invalid E-mail'))
def check_birthday(value): ''' Validate that a birthday must be a date, datetime or a DateTime in the past >>> check_birthday(DateTime('1969/7/21')) True >>> check_birthday(datetime(1969,7,21)) True >>> check_birthday(date(1969,7,21)) True >>> try: ... check_birthday(DateTime('2063/4/5')) ... except Invalid: ... print 'Invalid Date' Invalid Date >>> try: ... check_birthday(datetime(2063,4,5)) ... except Invalid: ... print 'Invalid Date' Invalid Date >>> try: ... check_birthday(date(2063,4,5)) ... except Invalid: ... print 'Invalid Date' Invalid Date >>> try: ... check_birthday('1999/12/31') ... except ValueError: ... print 'Invalid Date' Invalid Date ''' now = datetime.now().date() if isinstance(value, DateTime): value = value.asdatetime() if isinstance(value, datetime): value = value.date() if not isinstance(value, date): raise ValueError # Is in the past? delta = (now - value) if not delta.days > 0: raise Invalid(_(u"Birthday must be a date in the past.")) else: return True
from plone.i18n.normalizer.interfaces import IIDNormalizer from plone.namedfile.field import NamedImage from Products.CMFCore.utils import getToolByName from s17.person.utils import check_birthday from s17.person.catalog import IPersonCatalog from s17.person import MessageFactory as _ from plone.formwidget.namedfile.validator import NamedFileWidgetValidator from z3c.form import validator gender_options = SimpleVocabulary( [SimpleTerm(value=u'f', title=_(u'Female')), SimpleTerm(value=u'm', title=_(u'Male')), SimpleTerm(value=u'n/a', title=_(u'Rather not say'))]) def has_portrait(person): picture = person.picture return (picture and picture.getSize()) class IPerson(form.Schema): """ A representation of a Person """ given_name = schema.TextLine( title=_(u"First Name"),
from collective.z3cform.datagridfield import DataGridFieldFactory from collective.z3cform.datagridfield import DictRow from s17.person.content.person import IPerson from s17.person.catalog import IPersonCatalog from s17.person.utils import validate_email from s17.person.utils import validate_telephone from s17.person import MessageFactory as _ item_options = SimpleVocabulary( [SimpleTerm(value=u'work', title=_(u'Work')), SimpleTerm(value=u'home', title=_(u'Home'))]) im_options = SimpleVocabulary( [SimpleTerm(value=u'aim', title=_(u'AIM')), SimpleTerm(value=u'facebook', title=_(u'Facebook')), SimpleTerm(value=u'gadu-gadu', title=_(u'Gadu-Gadu')), SimpleTerm(value=u'gtalk', title=_(u'Google Talk')), SimpleTerm(value=u'icq', title=_(u'ICQ')), SimpleTerm(value=u'jabber', title=_(u'Jabber')), SimpleTerm(value=u'msn', title=_(u'MSN')), SimpleTerm(value=u'skype', title=_(u'Skype')), SimpleTerm(value=u'yahoo', title=_(u'Yahoo!'))])