Esempio n. 1
0
 def getBatchForm(self, objects, request):
     """Create batch based on objects no sorting for filter applied.
     """
     batchSize = request.get('batchSize',self.defaultBatchSize)
     if batchSize in ['', '0']:
         batchSize = 0
     else:
         batchSize = int(batchSize)
     start = int(request.get('start',0))
     resetStart = int(request.get('resetStart',0))
     lastindex = request.get('lastindex',0)
     navbutton = request.get('navbutton',None)
     if navbutton == "first" or resetStart:
         start = 0
     elif navbutton == "last":
         start=lastindex
     elif navbutton == "next":
         start = start + batchSize
         if start > lastindex: start = lastindex
     elif navbutton == "prev":
         start = start - batchSize
     elif request.has_key("nextstart"):
         start = request.nextstart
     if 0 < start > len(objects): start = 0
     request.start = start
     objects = ZTUtils.Batch(objects, batchSize or len(objects),
                 start=request.start, orphan=0)
     return objects
Esempio n. 2
0
 def getBatch(self, tableName, objects, **keys):
     """Filter, sort and batch objects and pass return set.
     """
     if log.isEnabledFor(logging.DEBUG):
         import os
         fmt = 'getBatch pid={0}, tableName={1}, {2} objects'
         pid = os.getpid()
         log.debug(fmt.format(pid, tableName, len(objects)))
     if not objects:
         objects = []
     tableState = self.setupTableState(tableName, **keys)
     if tableState.onlyMonitored and objects:
         objects = [o for o in objects if getattr(o, 'isMonitored', o.monitored)()]
     if tableState.filter and objects:
         objects = self.filterObjects(objects, tableState.filter,
                                     tableState.filterFields)
     # objects is frequently a generator.  Need a list in order to sort
     if not isinstance(objects, list):
         objects = list(objects)
     if tableState.sortedHeader:
         objects = self.sortObjects(objects, tableState)
     tableState.totalobjs = len(objects)
     tableState.buildPageNavigation(objects)
     if not hasattr(self.REQUEST, 'doExport'):
         objects = ZTUtils.Batch(objects,
                     tableState.batchSize or len(objects),
                     start=tableState.start, orphan=0)
     return objects