Changeset 816

Show
Ignore:
Timestamp:
03/02/07 03:03:07
Author:
chervol
Message:

getEntries optimized, added new navigation macros, shortened recent portlet code

Files:

Legend:

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

    r815 r816  
    3838                                       visible={'view' : 'invisible', 'edit':'invisible'}), 
    3939                default='descriptionOnly'), 
    40     IntegerField('displayItems',  
     40    IntegerField('displayItems', 
    4141                widget=IntegerWidget(label='BlogEntries to display',  
    4242                                      label_msgid="label_display_items", 
     
    268268        return [f for f in self.getBRefs('AppearsIn') if self.portal_membership.checkPermission('View', f)] 
    269269 
    270     def getEntries(self, category=None, maxResults=None, fromHere=0, filterState=1, sort=1, join=0, addCrossPostInfo=0, skipOnTop=0, **kwargs): 
     270    def getEntries(self, category=None, maxResults=None, b_start=0, filterState=1, join=0, skipOnTop=0, **kwargs): 
    271271        """ Return all the contained published entries, real objects, not the brains """ 
    272272        # see simpleblog_tool.searchForEntries for API description 
     
    283283        query['sort_on'] = 'effective' 
    284284        query['meta_type'] = 'BlogEntry' 
    285         if not skipOnTop: 
     285        onTop = [] 
     286        if not skipOnTop and b_start==0: 
    286287            query['getAlwaysOnTop']=1 
    287288            # first the items that need to be listed on top 
    288             localOnTop = self.portal_catalog.searchResults(query
    289             localOnTop = [r.getObject() for r in localOnTop ] 
     289            onTop = list(self.portal_catalog.searchResults(query)
     290            #onTop = [r.getObject() for r in localOnTop ] 
    290291            # then the other items 
    291292            query['getAlwaysOnTop']=0 
    292         else: 
    293             localOnTop = [] 
    294         localNoTop = self.portal_catalog.searchResults(query) 
    295         localNoTop= [r.getObject() for r in localNoTop] 
    296  
    297         onTop = localOnTop 
    298         onBottom = localNoTop 
     293 
     294        onBottom = list(self.portal_catalog.searchResults(query)) 
     295        #onBottom= [r.getObject() for r in localNoTop] 
     296         
     297        ####  cut the b_start when it is tooo large 
     298         
     299        last = 0 
    299300        if join: 
    300301            results = onTop+onBottom 
     302            if b_start > 0: 
     303                if len(onBottom)==b_start: 
     304                    b_start = b_start-(maxResults-b_start) 
     305                    last = 1 
     306                results = results[b_start:] 
    301307            if maxResults==0: 
     308                return (results,last) 
     309            elif maxResults==None: 
     310                results =[r.getObject() for r in  results[:self.simpleblog_tool.getMaxItemsInPortlet()]] 
    302311                return results 
    303             elif maxResults==None: 
    304                 return results[:self.simpleblog_tool.getMaxItemsInPortlet()] 
    305312            else: 
    306                 return results[:maxResults] 
     313                results = [r.getObject() for r in results] 
     314                return (results,last) 
    307315        else: 
    308             return (onTop, onBottom
     316            return ([r.getObject() for r in onTop], [r.getObject() for r in onBottom]
    309317 
    310318    def getAdminEmail(self): 
  • SimpleBlog/branches/optimizations/skins/SimpleBlog/simpleblog_portlet_macros.pt

    r815 r816  
    2424 
    2525<!-- macro used by the portlets to compile a list of recent additions --> 
    26 <div metal:define-macro="portletRecent"> 
    27      <tal:x tal:condition="maxItems|nothing"><tal:x tal:define="global maxResults maxItems"/> 
    28      </tal:x><tal:x tal:condition="not: maxItems|nothing"><tal:x tal:define="global maxResults python:0"/> 
    29      </tal:x><tal:block tal:define="maxResults python:test(maxResults==0,here.simpleblog_tool.getMaxItemsInPortlet(),maxResults);  
    30                                     recent python:startpoint.getEntries(maxResults=maxResults,skipOnTop=1, join=1); 
    31                                     global showIcons startpoint/getShowIcons;" 
    32      tal:omit-tag=""><tal:toggle tal:define="global toggle python:1"/> 
     26<div metal:define-macro="portletRecent"><tal:block  
     27           tal:define="maxResults here/simpleblog_tool/getMaxItemsInPortlet; 
     28                       recent python:startpoint.getEntries(maxResults=maxResults,skipOnTop=1, join=1); 
     29                       global showIcons startpoint/getShowIcons;"><tal:toggle  
     30           tal:define="global toggle python:1"/> 
    3331    <tal:entries tal:repeat="entry recent"> 
    3432        <tal:start tal:condition="python:inBlog and not solo"> 
     
    3634                     tal:condition="repeat/entry/start"  
    3735                     tal:attributes="class python:test(toggle, 'portletItem odd','portletItem even')"> 
    38             <tal:frontpage> 
    39                 <strong i18n:translate="recent_additions">Recent entries:</strong> 
    40             </tal:frontpage> 
     36        <strong i18n:translate="recent_additions">Recent entries:</strong> 
    4137        </dd></tal:start> 
    4238        <dd class="" 
     
    4844               tal:attributes="href entry/absolute_url;"  
    4945                               title="entry"> 
    50                <span tal:attributes="class python:showIcons and 'simpleBlogPortletIcons '+item_type_class or ''" tal:content="entry/title_or_id"/> 
     46               <span tal:attributes="class python:showIcons and 'simpleBlogPortletIcons '+item_type_class or ''" tal:content="entry/Title"/> 
    5147            </a><tal:toggle tal:define="global toggle python:test(toggle==1,0,1)"/> 
    5248        </dd> 
     
    5753            tal:condition="repeat/entry/end"  
    5854            tal:attributes="class python:test(toggle, className + ' even', className + ' odd')"> 
    59             <a href="#" tal:attributes="href string:${startpoint/absolute_url}/SimpleBlogFullSearch"  
     55            <a href="#" tal:attributes="href string:${startpoint/absolute_url}"  
    6056                           title="more..." 
    6157                           i18n:attributes="title box_morelink" 
  • SimpleBlog/branches/optimizations/skins/SimpleBlog/simpleblog_view.pt

    r815 r816  
    88      tal:define="displayItems python:here.getDisplayItems(); 
    99                  displayMode displayMode | python:here.getDisplayMode(); 
    10                   results python:here.getEntries(maxResults=0, sort=1, join=1, addCrossPostInfo=1); 
    1110                  b_size python:displayItems; 
    1211                  b_start python:0; 
    1312                  b_start request/b_start | b_start; 
    14                   Batch python:modules['Products.CMFPlone'].Batch;"> 
     13                  results python:here.getEntries(maxResults=int(b_start)+displayItems, sort=1, join=1, b_start=int(b_start)); 
     14                  last python:results[1]; 
     15                  b_start python:last and int(b_start)-displayItems or b_start; 
     16                  last python:len(results[0])<displayItems and 1 or last;"> 
    1517        <tal:block metal:use-macro="here/SimpleBlog_macros/macros/blogGlobals"/> 
    1618        <div metal:use-macro="here/document_actions/macros/document_actions"> 
     
    3537            Description 
    3638        </p> 
    37         <div tal:condition="results" tal:define="batch python:Batch(results, b_size, int(b_start), orphan=1);"> 
     39        <div tal:condition="results" tal:define="batch python:results[0];"> 
    3840            <tal:block tal:repeat="entry batch"><tal:entry  
    3941                       tal:define="obj python:entry;"><div metal:use-macro="here/SimpleBlog_macros/macros/?displayMode"/> 
    4042                <br/> 
    4143                </tal:entry></tal:block> 
    42             <div metal:use-macro="here/batch_macros/macros/navigation" /> 
     44            <div metal:use-macro="here/blog_navigation_macro/macros/navigation" /> 
    4345        </div> 
    4446        <tal:info tal:condition="not: results">