예제 #1
0
class IMember(IEmail):
    """
    Member
    """

    first_name = schema.TextLine(
        title=_(u'First Name'),
        required=True,
    )

    last_name = schema.TextLine(
        title=_(u'Last Name'),
        required=True,
    )

    homepage = schema.TextLine(
        # url format
        title=_(u'External Homepage'),
        required=False,
        constraint=is_url,
    )

    if PLONE5:
        directives.widget('bio', RichTextFieldWidget)
        bio = RichText(
            title=_(u'Biography'),
            required=False,
        )
    else:
        directives.widget(bio='plone.app.z3cform.wysiwyg.WysiwygFieldWidget')
        bio = schema.Text(
            title=_(u'Biography'),
            required=False,
        )
예제 #2
0
class IMember(IEmail):
    """
    Member
    """

    first_name = schema.TextLine(
        title=_(u"First Name"),
        required=True,
    )

    last_name = schema.TextLine(
        title=_(u"Last Name"),
        required=True,
    )

    homepage = schema.TextLine(
        # url format
        title=_(u"External Homepage"),
        required=False,
        constraint=is_url,
    )

    directives.widget(bio="plone.app.z3cform.wysiwyg.WysiwygFieldWidget")
    bio = schema.Text(
        title=_(u"Biography"),
        required=False,
    )
예제 #3
0
class IProvidePasswords(form.Schema):
    """Add password fields"""

    # Putting this in a separate fieldset for the moment:
    form.fieldset('membership', label=_(u"Membership"),
                  fields=['password', 'confirm_password'])

    # Note that the passwords fields are not required; this means we
    # can add members without having to add passwords at that time.
    # The password reset tool should hopefully be able to deal with
    # that.
    password = schema.Password(
        title=_(u"Password"),
        required=False,
    )

    confirm_password = schema.Password(
        title=_(u"Confirm Password"),
        required=False,
    )

    @invariant
    def password_matches_confirmation(data):
        """password field must match confirm_password field.
        """
        password = getattr(data, 'password', None)
        confirm_password = getattr(data, 'confirm_password', None)
        if (password or confirm_password) and (password != confirm_password):
            raise Invalid(_(u"The password and confirmation do not match."))

    form.omitted('password', 'confirm_password')
    form.no_omit(IAddForm, 'password', 'confirm_password')
예제 #4
0
class IProvidePasswordsSchema(model.Schema):
    """Add password fields"""

    # Note that the passwords fields are not required; this means we
    # can add members without having to add passwords at that time.
    # The password reset tool should hopefully be able to deal with
    # that.

    password = schema.Password(
        title=_(u"Password"),
        required=False,
    )

    confirm_password = schema.Password(
        title=_(u"Confirm Password"),
        required=False,
    )

    @invariant
    def password_matches_confirmation(data):
        """password field must match confirm_password field.
        """
        password = getattr(data, 'password', None)
        confirm_password = getattr(data, 'confirm_password', None)
        if not password and not confirm_password:
            return
        if password != confirm_password:
            raise Invalid(_(u"The password and confirmation do not match."))
        pwchecker = queryUtility(IPasswordChecker)
        if not pwchecker:
            return
        result = pwchecker.check(password)
        if result:
            raise Invalid(result)
예제 #5
0
 def password_matches_confirmation(data):
     """password field must match confirm_password field.
     """
     password = getattr(data, 'password', None)
     confirm_password = getattr(data, 'confirm_password', None)
     if (password or confirm_password) and (password != confirm_password):
         raise Invalid(_(u"The password and confirmation do not match."))
예제 #6
0
class IEmail(model.Schema):
    """Email address schema.

    If you have this field, we can make you a member.  To authenticate
    you also need a password though.
    """

    email = schema.TextLine(
        # String with validation in place looking for @, required.
        # Note that a person's email address will be their username.
        title=_(u"E-mail Address"),
        required=True,
        constraint=is_email,
    )

    @invariant
    def email_unique(data):
        """The email must be unique, as it is the login name (user name).

        The tricky thing is to make sure editing a user and keeping
        his email the same actually works.
        """
        user = data.__context__
        if user is not None:
            if hasattr(user, 'email') and user.email == data.email:
                # No change, fine.
                return
        error = validate_unique_email(data.email)
        if error:
            raise Invalid(error)
예제 #7
0
def is_email(value):
    """Is this an email address?

    We only do very basic validation, as the docs say we should just
    check if there is an '@' sign in the address.

    >>> is_email('*****@*****.**')
    True
    >>> is_email('joe')
    Traceback (most recent call last):
    ...
    Invalid: Not an email address
    >>> is_email('')
    Traceback (most recent call last):
    ...
    Invalid: Not an email address
    >>> is_email(None)
    Traceback (most recent call last):
    ...
    Invalid: Not an email address
    >>> is_email(object())
    Traceback (most recent call last):
    ...
    Invalid: Not an email address

    """
    if not isinstance(value, basestring) or '@' not in value:
        raise Invalid(_(u"Not an email address"))
    return True
 def password_matches_confirmation(data):
     """password field must match confirm_password field.
     """
     password = getattr(data, 'password', None)
     confirm_password = getattr(data, 'confirm_password', None)
     if (password or confirm_password) and (password != confirm_password):
         raise Invalid(_(u"The password and confirmation do not match."))
예제 #9
0
def validate_unique_email(email, context=None):
    """Validate this email as unique in the site.
    """
    if context is None:
        context = getSite()
    matches = get_brains_for_email(context, email)
    if not matches:
        # This email is not used yet.  Fine.
        return
    if len(matches) > 1:
        msg = "Multiple matches on email %s" % email
        logger.warn(msg)
        return msg
    # Might be this member, being edited.  That should have been
    # caught by our new invariant though, at least when changing the
    # email address through the edit interface instead of a
    # personalize_form.
    match = matches[0]
    try:
        found = match.getObject()
    except (AttributeError, KeyError, Unauthorized):
        # This is suspicious.  Best not to use this one.
        pass
    else:
        if found == context:
            # We are the only match.  Good.
            logger.debug("Only this object itself has email %s", email)
            return

    # There is a match but it is not this member or we cannot get
    # the object.
    msg = _("Email ${email} is already in use.", mapping={'email': email})
    logger.debug(msg)
    return msg
예제 #10
0
def validate_unique_email(email, context=None):
    """Validate this email as unique in the site.
    """
    if context is None:
        context = getSite()
    matches = get_brains_for_email(context, email)
    if not matches:
        # This email is not used yet.  Fine.
        return
    if len(matches) > 1:
        msg = "Multiple matches on email %s" % email
        logger.warn(msg)
        return msg
    # Might be this member, being edited.  That should have been
    # caught by our new invariant though, at least when changing the
    # email address through the edit interface instead of a
    # personalize_form.
    match = matches[0]
    try:
        found = match.getObject()
    except (AttributeError, KeyError, Unauthorized):
        # This is suspicious.  Best not to use this one.
        pass
    else:
        if found == context:
            # We are the only match.  Good.
            logger.debug("Only this object itself has email %s", email)
            return

    # There is a match but it is not this member or we cannot get
    # the object.
    msg = _("Email ${email} is already in use.", mapping={'email': email})
    logger.debug(msg)
    return msg
예제 #11
0
def is_email(value):
    """Is this an email address?

    We only do very basic validation, as the docs say we should just
    check if there is an '@' sign in the address.

    >>> is_email('*****@*****.**')
    True
    >>> is_email('joe')
    Traceback (most recent call last):
    ...
    Invalid: Not an email address
    >>> is_email('')
    Traceback (most recent call last):
    ...
    Invalid: Not an email address
    >>> is_email(None)
    Traceback (most recent call last):
    ...
    Invalid: Not an email address
    >>> is_email(object())
    Traceback (most recent call last):
    ...
    Invalid: Not an email address

    """
    if not isinstance(value, basestring) or not '@' in value:
        raise Invalid(_(u"Not an email address"))
    return True
예제 #12
0
class IProvidePasswords(IProvidePasswordsSchema):
    """Add password fields"""

    # Putting this in a separate fieldset for the moment:
    form.fieldset('membership', label=_(u"Membership"),
                  fields=['password', 'confirm_password'])

    form.omitted('password', 'confirm_password')
    form.no_omit(IAddForm, 'password', 'confirm_password')
예제 #13
0
 def password_matches_confirmation(data):
     """password field must match confirm_password field.
     """
     password = getattr(data, 'password', None)
     confirm_password = getattr(data, 'confirm_password', None)
     if not password and not confirm_password:
         return
     if password != confirm_password:
         raise Invalid(_(u"The password and confirmation do not match."))
     pwchecker = queryUtility(IPasswordChecker)
     if not pwchecker:
         return
     result = pwchecker.check(password)
     if result:
         raise Invalid(result)
예제 #14
0
 def password_matches_confirmation(data):
     """password field must match confirm_password field.
     """
     password = getattr(data, 'password', None)
     confirm_password = getattr(data, 'confirm_password', None)
     if not password and not confirm_password:
         return
     if password != confirm_password:
         raise Invalid(_(u"The password and confirmation do not match."))
     pwchecker = queryUtility(IPasswordChecker)
     if not pwchecker:
         return
     result = pwchecker.check(password)
     if result:
         raise Invalid(result)
예제 #15
0
def is_url(value):
    """Is this a URL?

    >>> is_url("http://google.com/")
    True
    >>> is_url("https://google.com")
    True
    >>> is_url("http://example.org/folder/somepage")
    True
    >>> is_url("ssh://google.com")
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url("nothing")
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url("")
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url(None)
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url(object())
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link

    """
    if isinstance(value, basestring):
        pattern = re.compile(r"^https?://[^\s\r\n]+")
        if pattern.search(value.strip()):
            return True
    raise Invalid(_(u"Not a valid link"))
예제 #16
0
def is_url(value):
    """Is this a URL?

    >>> is_url("http://google.com/")
    True
    >>> is_url("https://google.com")
    True
    >>> is_url("http://example.org/folder/somepage")
    True
    >>> is_url("ssh://google.com")
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url("nothing")
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url("")
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url(None)
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link
    >>> is_url(object())
    Traceback (most recent call last):
    ...
    Invalid: Not a valid link

    """
    if isinstance(value, basestring):
        pattern = re.compile(r"^https?://[^\s\r\n]+")
        if pattern.search(value.strip()):
            return True
    raise Invalid(_(u"Not a valid link"))
예제 #17
0
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from five import grok
from zope.schema.interfaces import IVocabularyFactory
from incf.countryutils import data as countrydata
from dexterity.membrane import _


province_type=[
                  ('Hunan','Hunan',_(u'Hunan')),
                  ('hubei','hubei',_(u'Hubei')),
                  ('beijing','beijing',_(u'Beijing')),
                  ('heilongjiang','heilongjiang',_(u'heilongjiang')),
                  ('jilin','jilin',_(u'Jilin')),  
                  ('liaolin','liaolin',_(u'liaolin')),
                  ('shandong','shandong',_(u'Shandong')),
                  ('shanxi','shanxi',_(u'Shanxi')),
                  ('hebei','hebei',_(u'Heber')),
                  ('henan','henan',_(u'Henan')),
                  ('neimenggu','neimenggu',_(u'Neimenggu')),  
                  ('xinqiang','xinqiang',_(u'Xinqiang')),
                  ('Qinghai','Qinghai',_(u'Qinghai')),
                  ('Xizang','Xizang',_(u'Xizang')),
                  ('Shanxi','Shanxi',_(u'Shanxi')),
                  ('Tianjin','Tianjin',_(u'Tianjin')),
                  ('Shanghai','Shanghai',_(u'Shanghai')),  
                  ('Anhui','Anhui',_(u'Anhui')),
                  ('Jiangsu','Jiangsu',_(u'Jiangsu')),
                  ('Zhejiang','Zhejiang',_(u'Zhejiang')),
                  ('Sichuan','Sichuan',_(u'Sichuan')),
                  ('Fujian','Fujian',_(u'Fujian')),
                  ('Guangdong','Guangdong',_(u'Guangdong')),  
예제 #18
0
def maxPhotoSize(value):
    if value is not None:
        if value.getSize()/1024 > 512:
            raise schema.ValidationError(_(u"Please upload image smaller than 512KB"))