예제 #1
0
 def update(self):
     context = aq_inner(self.context)
     self.errors = {}
     unwanted = ('_authenticator', 'form.button.Submit')
     required = ('subject', 'email')
     if 'form.button.Submit' in self.request:
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         form = self.request.form
         form_data = {}
         form_errors = {}
         errorIdx = 0
         for value in form:
             if value not in unwanted:
                 form_data[value] = safe_unicode(form[value])
                 if not form[value] and value in required:
                     error = {}
                     error['active'] = True
                     error['msg'] = _(u"This field is required")
                     form_errors[value] = error
                     errorIdx += 1
                 else:
                     error = {}
                     error['active'] = False
                     error['msg'] = form[value]
                     form_errors[value] = error
         if errorIdx > 0:
             self.errors = form_errors
         else:
             self._create_workspace(form)
예제 #2
0
def is_url(value):
    """ Is this a URL? """
    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"))
예제 #3
0
 def available_services(self):
     services = {
         u'google': _(u"Google Analytics"),
         u'xovi': _(u"XOVI"),
         u'ac': _(u"activeCollab"),
     }
     data = []
     for s in services:
         item = {}
         req_key = 'xeo.cxn.{0}_api_uri'.format(s)
         api_uri = api.portal.get_registry_record(req_key)
         item['name'] = services[s]
         item['sid'] = s
         item['uri'] = api_uri
         data.append(item)
     return data
예제 #4
0
def is_email(value):
    """ Is this an email address? """
    if not isinstance(value, basestring) or not '@' in value:
        raise Invalid(_(u"Not an email address"))
    return True