Esempio n. 1
0
    def items(self, user=None, tag=None, search_all=False, type_=None):

        # batch paging
        b_start = int(self.request.form.get('b_start', 0))
        b_size = int(self.request.form.get('b_size', 10))

        # filter
        if not user:
            user = safe_decode(self.request.form.get('user'))
        if not tag:
            tag = safe_decode(self.request.form.get('tag'))
        if not search_all:
            search_all = self.request.form.get('search_all')

        if not type_ and 'type' in self.request.form:
            type_ = self.request.form['type']
        if type_:
            ty = type_.lower()
            if ty == 'event':
                type_ = IEvent.__identifier__
            elif ty == 'thread':
                type_ = IThread.__identifier__
            elif ty == 'place':
                type_ = IPlace.__identifier__
            else:
                type_ = None
        else:
            # if no other type is given, search for IBasetype
            type_ = IBasetype.__identifier__

        query = {}

        query['object_provides'] = type_
        query['sort_on'] = 'created'
        query['sort_order'] = 'reverse'

        if not search_all:
            query['path'] = {'query': '/'.join(self.context.getPhysicalPath())}
        if user:
            query['Creator'] = user
        if tag:
            query['Subject'] = tag

        cat = getToolByName(self.context, 'portal_catalog')
        result = cat(batch=True, **query)
        return Batch(result, size=b_size, start=b_start)
Esempio n. 2
0
 def __setattr__(self, name, value):
     fl = self._feature_list
     bm = self._behavior_map
     if name in fl:  # set the features by adding/removing behaviors
         object.__setattr__(self, name, value)
     elif name in bm:  # set the attributes on behaviors
         behavior = bm[name](self.context, None)
         if behavior:
             # all strings go unicode
             value = safe_decode(value)
             setattr(behavior, name, value)
Esempio n. 3
0
    def plaintext(self):
        behavior = IBase(self.context, None)
        value = getattr(behavior, "text", None)
        ## TODO: reenable transform
        # return value

        # if isinstance(value, RichTextValue):
        #    site = getSite()
        #    trans = ITransformer(site)
        #    value = trans(value, 'text/plain')

        if value:
            value = safe_encode(value)
            pt = getToolByName(self.context, "portal_transforms")
            data = pt.convertTo("text/plain", value, mimetype="text/html")
            text = data.getData()
            return safe_decode(text)
        return None