Exemple #1
0
 def getPlominoReaders(self):
     """
     """
     if self.hasItem('Plomino_Readers'):
         return asList(self.Plomino_Readers)
     else:
         return ['*']
Exemple #2
0
    def tojson(self):
        """Returns a JSON representation of view data 
        """
        data = []
        categorized = self.getCategorized()
        
        columnids = [col.id for col in self.getColumns() if not getattr(col, 'HiddenColumn', False)]
        for b in self.getAllDocuments(getObject=False):
            row = [b.getPath().split('/')[-1]]
            for colid in columnids:
                v = getattr(b, self.getIndexKey(colid), '')
                if isinstance(v, list):
                    v = [asUnicode(e).encode('utf-8').replace('\r', '') for e in v]
                else:
                    v = asUnicode(v).encode('utf-8').replace('\r', '')
                row.append(v or ' ')

            if categorized:
                for cat in asList(row[1]):
                    entry = [c for c in row]
                    entry[1] = cat
                    data.append(entry)
            else:
                data.append(row)
        return json.dumps({ 'aaData': data })
Exemple #3
0
 def getPlominoReaders(self):
     """ Return list of readers; if none set, everyone can read.
     """
     if self.hasItem('Plomino_Readers'):
         return asList(self.getItem('Plomino_Readers'))
     else:
         return ['*']
Exemple #4
0
    def tojson(self, REQUEST=None):
        """ Returns a JSON representation of view data
        """
        data = []
        categorized = self.getCategorized()
        start = 1
        limit = -1
        search = None
        sort_index = None
        reverse = None
        if REQUEST:
            REQUEST.RESPONSE.setHeader(
                    'content-type', 'application/json; charset=utf-8')
            start = int(REQUEST.get('iDisplayStart', 1))
            iDisplayLength = REQUEST.get('iDisplayLength', None)
            if iDisplayLength:
                limit = int(iDisplayLength)
            search = REQUEST.get('sSearch', '').lower()
            if search:
                search = ' '.join([term+'*' for term in search.split(' ')])
            sort_column = REQUEST.get('iSortCol_0')
            if sort_column:
                sort_index = self.getIndexKey(
                        self.getColumns()[int(sort_column)-1].id)
            reverse = REQUEST.get('sSortDir_0', None)
            if reverse == 'desc':
                reverse = 0
            if reverse == 'asc':
                reverse = 1
        if limit < 1:
            limit = None

        if not REQUEST is None and 'request_query' in REQUEST:
            # query parameter in REQUEST is supposed to be a json object
            request_query = self.__query_loads__(REQUEST['request_query'])
        else:
            request_query = None

        results = self.getAllDocuments(
                start=start,
                limit=limit,
                getObject=False,
                fulltext_query=search,
                sortindex=sort_index,
                reverse=reverse,
                request_query=request_query)
        total = display_total = len(results)
        columns = [column for column in self.getColumns()
                if not getattr(column, 'HiddenColumn', False)]
        for brain in results:
            row = [brain.getPath().split('/')[-1]]
            for column in columns:
                column_value = getattr(brain, self.getIndexKey(column.id), '')
                rendered = column.getColumnRender(column_value)
                if isinstance(rendered, list):
                    rendered = [asUnicode(e).encode('utf-8').replace('\r', '') for e in rendered]
                else:
                    rendered = asUnicode(rendered).encode('utf-8').replace('\r', '')
                row.append(rendered or '&nbsp;')
            if categorized:
                for cat in asList(row[1]):
                    entry = [c for c in row]
                    entry[1] = cat
                    data.append(entry)
            else:
                data.append(row)
        return json.dumps(
                    {'iTotalRecords': total,
                    'iTotalDisplayRecords': display_total,
                    'aaData': data })
Exemple #5
0
 def tojson(self, REQUEST=None):
     """ Returns a JSON representation of view data 
     """
     data = []
     categorized = self.getCategorized()
     start = 1
     limit = -1
     search = None
     sort_index = None
     reverse = None
     if REQUEST:
         start = int(REQUEST.get('iDisplayStart', 1))
         iDisplayLength = REQUEST.get('iDisplayLength', None)
         if iDisplayLength:
             limit = int(iDisplayLength)
         search = REQUEST.get('sSearch', '').lower()
         if search:
             search = ' '.join([term + '*' for term in search.split(' ')])
         sort_column = REQUEST.get('iSortCol_0')
         if sort_column:
             sort_index = self.getIndexKey(
                 self.getColumns()[int(sort_column) - 1].id)
         reverse = REQUEST.get('sSortDir_0', None)
         if reverse == 'desc':
             reverse = 0
         if reverse == 'asc':
             reverse = 1
     if limit < 1:
         limit = None
     results = self.getAllDocuments(start=start,
                                    limit=limit,
                                    getObject=False,
                                    fulltext_query=search,
                                    sortindex=sort_index,
                                    reverse=reverse)
     total = display_total = len(results)
     columnids = [
         col.id for col in self.getColumns()
         if not getattr(col, 'HiddenColumn', False)
     ]
     for b in results:
         row = [b.getPath().split('/')[-1]]
         for colid in columnids:
             v = getattr(b, self.getIndexKey(colid), '')
             if isinstance(v, list):
                 v = [
                     asUnicode(e).encode('utf-8').replace('\r', '')
                     for e in v
                 ]
             else:
                 v = asUnicode(v).encode('utf-8').replace('\r', '')
             row.append(v or '&nbsp;')
         if categorized:
             for cat in asList(row[1]):
                 entry = [c for c in row]
                 entry[1] = cat
                 data.append(entry)
         else:
             data.append(row)
     return json.dumps({
         'iTotalRecords': total,
         'iTotalDisplayRecords': display_total,
         'aaData': data
     })
Exemple #6
0
                    # We may be calling save with 'creation=True' on
                    # existing documents, in which case we may already have
                    # a title.
                    self.setTitle(title)

            # update the document id
            if creation and form.getDocumentId():
                new_id = self.generateNewId()
                if new_id:
                    transaction.savepoint(optimistic=True)
                    db.documents.manage_renameObject(self.id, new_id)

        # update the Plomino_Authors field with the current user name
        if asAuthor:
            # getItem('Plomino_Authors', []) might return '' or None
            authors = asList(self.getItem('Plomino_Authors') or [])
            name = db.getCurrentMember().getUserName()
            if name not in authors:
                authors.append(name)
            self.setItem('Plomino_Authors', authors)

        # execute the onSaveDocument code of the form
        if form and onSaveEvent:
            try:
                result = self.runFormulaScript(
                    SCRIPT_ID_DELIMITER.join(['form', form.id, 'onsave']),
                    self, form.onSaveDocument)
                if result and hasattr(self, 'REQUEST'):
                    self.REQUEST.set('plominoredirecturl', result)
            except PlominoScriptException, e:
                if hasattr(self, 'REQUEST'):
Exemple #7
0
    def tojson(self, REQUEST=None):
        """ Returns a JSON representation of view data
        """
        data = []
        categorized = self.getCategorized()
        start = 1
        limit = -1
        search = None
        sort_index = None
        reverse = None
        if REQUEST:
            REQUEST.RESPONSE.setHeader('content-type',
                                       'application/json; charset=utf-8')
            start = int(REQUEST.get('iDisplayStart', 1))
            iDisplayLength = REQUEST.get('iDisplayLength', None)
            if iDisplayLength:
                limit = int(iDisplayLength)
            search = REQUEST.get('sSearch', '').lower()
            if search:
                search = ' '.join([term + '*' for term in search.split(' ')])
            sort_column = REQUEST.get('iSortCol_0')
            if sort_column:
                sort_index = self.getIndexKey(
                    self.getColumns()[int(sort_column) - 1].id)
            reverse = REQUEST.get('sSortDir_0', None)
            if reverse == 'desc':
                reverse = 0
            if reverse == 'asc':
                reverse = 1
        if limit < 1:
            limit = None

        if not REQUEST is None and 'request_query' in REQUEST:
            # query parameter in REQUEST is supposed to be a json object
            request_query = self.__query_loads__(REQUEST['request_query'])
        else:
            request_query = None

        results = self.getAllDocuments(start=start,
                                       limit=limit,
                                       getObject=False,
                                       fulltext_query=search,
                                       sortindex=sort_index,
                                       reverse=reverse,
                                       request_query=request_query)
        total = display_total = len(results)
        columns = [
            column for column in self.getColumns()
            if not getattr(column, 'HiddenColumn', False)
        ]
        for brain in results:
            row = [brain.getPath().split('/')[-1]]
            for column in columns:
                column_value = getattr(brain, self.getIndexKey(column.id), '')
                rendered = column.getColumnRender(column_value)
                if isinstance(rendered, list):
                    rendered = [
                        asUnicode(e).encode('utf-8').replace('\r', '')
                        for e in rendered
                    ]
                else:
                    rendered = asUnicode(rendered).encode('utf-8').replace(
                        '\r', '')
                row.append(rendered or '&nbsp;')
            if categorized:
                for cat in asList(row[1]):
                    entry = [c for c in row]
                    entry[1] = cat
                    data.append(entry)
            else:
                data.append(row)
        return json.dumps({
            'iTotalRecords': total,
            'iTotalDisplayRecords': display_total,
            'aaData': data
        })