Changeset 844
- Timestamp:
- 04/17/07 10:27:50
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
SimpleBlog/branches/optimizations/content/blog.py
r841 r844 260 260 return [f for f in self.getBRefs('AppearsIn') if self.portal_membership.checkPermission('View', f)] 261 261 262 def buildBatch(self, b_start): 263 """Return batch for navigation""" 264 len = self._count() 265 ditems = self.getDisplayItems() 266 max_pages = len/ditems 267 batch = [] 268 if max_pages: 269 vis_middle = 3 # max number of pages in one of the side around current 270 curr_num = b_start/ditems >= max_pages and max_pages or b_start/ditems+1 271 # first page (when current page far from 1st page) 272 first = [] 273 if curr_num-vis_middle > 2: 274 first = [1,"b_start=0"] 275 batch.append(first) 276 # last page (when current page far from terminal page) 277 last = [] 278 if max_pages-curr_num > vis_middle+1: 279 last = [max_pages,"b_start=%d" % ((max_pages-1)*ditems)] 280 batch.append(last) 281 # form batch around current page 282 lft_bound = curr_num-vis_middle > 2 and curr_num-vis_middle or 1 283 rght_bound = max_pages-curr_num > vis_middle+1 and curr_num+vis_middle or max_pages 284 lst = [] 285 for p in range(lft_bound, rght_bound+1): 286 q = p!=curr_num and "b_start=%d" % ((p-1)*ditems) or "" 287 lst.append([p,q]) 288 batch.append(lst) 289 return batch 290 291 def getStart(self): 292 """ Validate b_start from request and return right value.""" 293 request = self.REQUEST 294 try: 295 b_start = int(request.get('b_start', 0)) or 0 296 except: 297 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: 303 b_start = 0 304 else: 305 b_start = (b_start % ditems)!=0 and (b_start/ditems)*ditems or b_start 306 return b_start 307 262 308 def getEntries(self, category=None, maxResults=None, b_start=0, filterState=1, join=0, skipOnTop=0, mode="", **kwargs): 263 309 """ Return all the contained published entries, real objects, not the brains """ … … 282 328 283 329 onBottom = list(self.portal_catalog.searchResults(query)) 330 batch = 'navigation' in query.keys() and self.buildBatch(b_start) or [] 284 331 #### cut the b_start when it is tooo large 285 332 … … 299 346 last = 1 300 347 results = results[b_start:] 301 if mode == "full": 302 results = (results,last) 303 else: 304 results = (results,last) 305 return results 348 return (results,last,batch) 306 349 else: 307 return (onTop, onBottom )350 return (onTop, onBottom, batch) 308 351 309 352 def getAdminEmail(self): SimpleBlog/branches/optimizations/skins/SimpleBlog/blog_navigation_macros.pt
r816 r844 5 5 <div class="listingBar" 6 6 metal:define-macro="navigation" 7 tal:define="url string:${here/absolute_url};"> 7 tal:define="url string:${here/absolute_url}; 8 nav python:results[2]; 9 first_item python:nav[0]; 10 last_item python:nav[1]; 11 batch python:nav[2];"> 12 8 13 <span class="previous" 9 14 tal:condition="python:int(b_start)>0"> … … 26 31 </a> 27 32 </span> 33 34 <!-- Link to first --> 35 <span tal:condition="first_item"> 36 <a href="" 37 tal:define="query python:first_item[1];" 38 tal:attributes="href python: '%s?%s' % (url, query);">1</a> 39 ... 40 </span> 41 42 <!-- Pagelist with links to previous pages for quick navigation --> 43 <span tal:condition="batch" 44 tal:repeat="linklist batch" 45 tal:omit-tag="" > 46 <a href="" 47 tal:define="page python:linklist[0]; 48 query python:linklist[1];" 49 tal:content="page" 50 tal:attributes="href python: '%s?%s' % (url,query)" 51 tal:omit-tag="not:query" > 52 </a> 53 </span> 54 55 <!-- Link to last --> 56 <span tal:condition="last_item"> 57 ... 58 <a href="" 59 tal:define="page python:last_item[0]; 60 query python:last_item[1];" 61 tal:attributes="href python: '%s?%s' % (url,query);" 62 tal:content="page">3457</a> 63 </span> 64 28 65 </div> 66 29 67 </body> 30 68 </html> SimpleBlog/branches/optimizations/skins/SimpleBlog/simpleblog_view.pt
r823 r844 6 6 <div metal:fill-slot="main"> 7 7 <tal:main-macro metal:define-macro="main" 8 tal:define="display Items python:here.getDisplayItems();9 display Mode displayMode | python:here.getDisplayMode();8 tal:define="displayMode displayMode | python:here.getDisplayMode(); 9 displayItems python:here.getDisplayItems(); 10 10 b_size python:displayItems; 11 b_start python:int(request.get('b_start', 0)) or 0; 12 b_start python:(b_start%displayItems)!=0 and (b_start/displayItems)*displayItems or b_start; 13 results python:here.getEntries(maxResults=b_start+displayItems, sort=1, join=1, b_start=b_start,mode=displayMode); 14 last python:results[1]"> 11 b_start here/getStart; 12 results python:here.getEntries(maxResults=b_start+displayItems, sort=1, join=1, b_start=b_start,mode=displayMode,navigation=1); 13 last python:results[1];"> 15 14 <tal:block metal:use-macro="here/SimpleBlog_macros/macros/blogGlobals"/> 16 15 <div metal:use-macro="here/document_actions/macros/document_actions"> … … 40 39 <br/> 41 40 </tal:entry></tal:block> 42 <div metal:use-macro="here/blog_navigation_macros/macros/navigation" /> 41 <div metal:use-macro="here/blog_navigation_macros/macros/navigation" 42 tal:condition="python:results[2]"/> 43 43 </div> 44 44 <tal:info tal:condition="not: results">
