Changeset 869

Show
Ignore:
Timestamp:
05/22/07 08:42:30
Author:
mylan
Message:

Fix batching bugs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • SimpleBlog/branches/optimizations/content/blog.py

    r867 r869  
    260260        return [f for f in self.getBRefs('AppearsIn') if self.portal_membership.checkPermission('View', f)] 
    261261 
    262     def buildBatch(self, b_start): 
     262    def buildBatch(self, b_start, query, notlimited_len): 
    263263        """Return batch for navigation""" 
    264         len = self._count() 
     264        #if 'getAlwaysOnTop' in query.keys(): 
     265            #query['getAlwaysOnTop']=1 
     266            #len1 = len(self.portal_catalog(**query)) 
     267            #query['getAlwaysOnTop']=0 
     268        if 'sort_limit' in query.keys(): 
     269            del query['sort_limit'] 
     270            total_len = len(self.portal_catalog(**query)) 
     271        else: 
     272            total_len = notlimited_len 
    265273        ditems = self.getDisplayItems() 
    266         max_pages = len/ditems 
     274        max_pages = total_len/ditems + (total_len%ditems and 1 or 0) 
    267275        batch = [] 
    268276        if max_pages: 
     
    296304        except: 
    297305            b_start = 0 
    298         ditems = self.getDisplayItems() 
    299         count = self._count() 
    300         if b_start > count: 
    301             b_start = count - (count % ditems) 
    302         elif b_start < 0: 
     306        if b_start < 0: 
    303307            b_start = 0 
    304         else: 
    305             b_start = (b_start % ditems)!=0 and (b_start/ditems)*ditems or b_start 
    306308        return b_start 
    307309 
     
    328330 
    329331        onBottom = list(self.portal_catalog.searchResults(query)) 
    330         batch = 'navigation' in query.keys() and self.buildBatch(b_start) or [] 
    331332        ####  cut the b_start when it is tooo large 
    332  
    333333        itemsPerPage = self.getDisplayItems() 
    334334        last = 0 
     
    341341        if join: 
    342342            results = onTop+onBottom 
     343            batch = 'navigation' in query.keys() and self.buildBatch(b_start, query, len(results)) or [] 
    343344            if b_start > 0: 
    344345                if len(onBottom) == b_start: 
     
    348349            return (results,last,batch) 
    349350        else: 
     351            batch = 'navigation' in query.keys() and self.buildBatch(b_start, query, len(onBottom)) or [] 
    350352            return (onTop, onBottom, batch) 
    351353