def _batch_for_page(self, pagenumber): """Return a new Batch object for the given pagenumber. """ new_batch = Batch.fromPagenumber(self.batch._sequence, pagesize=self.b_size, pagenumber=pagenumber) return new_batch
def search(self): """ A traversable method to search for users""" query = self.request.get('q', None) page = int(self.request.get('page', 1)) pagesize = int(self.request.get('pagesize', 20)) if not query: return json.dumps({}) source = self.get_user_source() batch = Batch.fromPagenumber(items=source.search(query), pagesize=pagesize, pagenumber=page) def _term_to_dict(term): return { '_resultId': term.token, 'id': term.token, 'text': term.title and term.title or term.token } return json.dumps({ 'results': map(_term_to_dict, batch), 'total_count': len(batch), 'page': page, 'pagination': { 'more': (page * pagesize) < len(batch) } })
def search(self): """ A traversable method to search for users""" query = self.request.get('q', None) page = int(self.request.get('page', 1)) pagesize = int(self.request.get('pagesize', 20)) if not query: return json.dumps({}) source = AllUsersSource(api.portal.get()) batch = Batch.fromPagenumber(items=source.search(query), pagesize=pagesize, pagenumber=page) def _term_to_dict(term): return {'_resultId': term.token, 'id': term.token, 'text': term.title and term.title or term.token} return json.dumps( { 'results': map(_term_to_dict, batch), 'total_count': len(batch), 'page': page, 'pagination': {'more': (page * pagesize) < len(batch)} } )
def _batch_for_page(self, pagenumber): """Return a new Batch object for the given pagenumber. """ new_batch = Batch.fromPagenumber( self.batch._sequence, pagesize=self.b_size, pagenumber=pagenumber) return new_batch
def results(self): """ Return the list of objects stored in the tile. """ self.set_limit() uuids = self.data.get('uuids', None) results = [] if uuids: uuids = [uuids] if type(uuids) == str else uuids for uid in uuids: obj = uuidToObject(uid) if obj: results.append(obj) else: self.remove_item(uid) final_result = [] batch = Batch.fromPagenumber(items=results, pagesize=4, pagenumber=1) for num in batch.navlist: batch.pagenumber = num final_result.append(list(batch)) return final_result
def results(self): """ Return the list of objects stored in the tile. """ self.set_limit() uuids = self.data.get('uuids', None) results = [] if uuids: uuids = [uuids] if type(uuids) == str else uuids for uid in uuids: obj = uuidToObject(uid) if obj: results.append(obj) else: self.remove_item(uid) final_result = [] batch = Batch.fromPagenumber(items=results, pagesize=4, pagenumber=1) for num in batch.navlist: batch.pagenumber = num final_result.append(list(batch)) return final_result