from zope.interface import Interface, Attribute from zope import schema from zope.annotation.interfaces import IAttributeAnnotatable from zope.app.container.interfaces import IContainer from zope.app.component.interfaces import IPossibleSite from zope.component.interfaces import IObjectEvent from zope.i18nmessageid import MessageFactory _ = MessageFactory('krihvel') class IKrihvelBase(Interface): """ Marker interface Krihvel base interface. Atleast all content types must implement this or interface they implement """ class IMembersFolder(IKrihvelBase, IContainer, IAttributeAnnotatable): """ Members folder - contains member home folders """ class IMemberFolder(IKrihvelBase, IContainer, IAttributeAnnotatable): """ Members folder - contains member home folders """ class IManagementFolder(IKrihvelBase, IContainer, IAttributeAnnotatable): """ Management folder - pace for calling out management pages """ class IKrihvel(IKrihvelBase, IContainer, IPossibleSite, IAttributeAnnotatable): """Interface used to define what methods the object provides, as well as which fields are available.""" title = schema.TextLine(title=_(u"Krihvel site title")) description = schema.Text(title=_(u"Krihvel site description")) def getTitle(): """Returns the instance title.""" def getDescription(): """ Returns the instance description. """ class INewKrihvelSiteEvent(IObjectEvent): """Indicates that new Krihvel site has been created""" import re from zope.schema import ValidationError from zope.schema.vocabulary import SimpleVocabulary class NotAnEmailAddress(ValidationError): __doc__ = _(u"This is not a valid email address") regex = r"[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+\.)*[a-zA-Z]{2,4}" check_email = re.compile(regex).match def validate_email(value): if not check_email(value): raise NotAnEmailAddress(value) return True class IMemberInfo(IKrihvelBase): firstname = schema.TextLine( title=_(u"First name"), required=True ) lastname = schema.TextLine( title=_(u"Last name"), required=True ) email = schema.TextLine( title=_(u"Email address"), required=False, constraint=validate_email ) gender = schema.Choice( title=_(u"Gender"), vocabulary=SimpleVocabulary.fromValues([_(u"Woman"),_(u"Man")]), required=True ) biography = schema.Text( title=_(u"Biography"), required=False ) homepage = schema.URI( title=_(u"Homepage"), required=False )