Changeset 841

Show
Ignore:
Timestamp:
04/11/07 05:20:09
Author:
mylan
Message:

Clean-up code code.

Files:

Legend:

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

    r838 r841  
    1818    meta_type= 'SimpleBlog manager'  
    1919    plone_tool = 1 
    20          
     20 
    2121    manage_options=PropertyManager.manage_options 
    22      
     22 
    2323    security = ClassSecurityInfo() 
    2424    calendar_types=['BlogEntry'] 
    2525    use_session="" 
    26      
     26 
    2727    def __init__(self): 
    2828        self.manage_addProperty('publishedState', 'published', 'string') 
     
    7676        except: 
    7777            return [] 
    78          
     78 
    7979    def _getCreatePortletOnBlogCreation(self): 
    8080        try: 
     
    100100 
    101101        self.globalCategories=value 
    102      
     102 
    103103    security.declarePublic('getPublishedState') 
    104104    def getPublishedState(self): 
    105105        return self._getState() 
    106      
    107      
     106 
    108107    security.declarePublic('getMaxItemsInPortlet') 
    109108    def getMaxItemsInPortlet(self): 
    110109        return self._getMaxItemsInPortlet() 
    111      
     110 
    112111    security.declarePublic('getFrontPage') 
    113112    def getFrontPage(self, context): 
     
    127126                    break 
    128127                parent=parent.aq_parent 
    129              
     128 
    130129            if found==1: 
    131130                return parent 
     
    142141        """ 
    143142        plone_utils = getToolByName(context, 'plone_utils') 
    144          
     143 
    145144        startpoint = self.getFrontPage(context) 
    146145        if not startpoint: 
     
    152151        else: 
    153152            return startpoint 
    154       
     153 
    155154    security.declarePublic('getAvailableCategories') 
    156155    def getAvailableCategories(self, context, startpoint=None): 
     
    162161        # if we are higher in the tree than any Blog then we will end up in the portalobject itself 
    163162        # in that case we just search for categories starting in context. 
    164          
    165          
    166163        if not startpoint: 
    167164            startpoint = self.getStartpoint(context, fromHere=0) 
     
    169166        path = self.getObjectPath(startpoint) 
    170167 
    171         # now we have the starting point for our search 
    172          
    173         #result = startpoint.portal_catalog.searchResults(meta_type=['BlogFolder', 'Blog'], path={'query':self.getObjectPath(startpoint),'level':0}) 
    174          
    175         # now fetch all the available categories 
    176         #categories=[] 
    177         #for o in result: 
    178         #    obj=o.getObject() 
    179         #    cats = obj.getCategories() 
    180         #    for c in cats: 
    181         #        if not c in categories: 
    182         #            categories.append(c) 
    183         # 
    184         # add the global categories 
    185         #for c in self.getGlobalCategories(): 
    186         #    if not c in categories: 
    187         #        categories.append(c) 
    188          
    189168        # now we have a list of unique categories available from startpoint and deeper in tree 
    190169        # next step is to count the number of entries for each category 
     
    196175                rescats[c]=len(result) 
    197176        return rescats 
    198         #return categories 
    199      
     177 
    200178    security.declarePublic('getSortedKeys') 
    201179    def getSortedKeys(self, dict): 
     
    203181        keys.sort() 
    204182        return keys 
    205      
     183 
    206184    security.declarePublic('getGlobalCategories') 
    207185    def getGlobalCategories(self): 
    208186        return self._getGlobalCategories() 
    209      
     187 
    210188    security.declarePublic('getStartpoint') 
    211189    def getStartpoint(self, context, fromHere=0): 
     
    222200                    break 
    223201                parent=parent.aq_parent 
    224              
     202 
    225203            if found==1: 
    226204                startpoint=parent 
     
    234212 
    235213        return startpoint 
    236      
     214 
    237215    security.declarePublic('searchForEntries') 
    238216    def searchForEntries(self, context, category=None, maxResults=None, fromHere=0, filterState=1, **kwargs): 
     
    240218        # leave it to None to get the max from the properties 
    241219        # set fromHere=1 to search from the current location. Is used for BlogFolders 
    242          
     220 
    243221        # first, get the context right 
    244222        # when inside a Blog: search for the frontpage 
    245223        # when outside a Blog: use context (or its container) 
    246          
     224 
    247225        #filterState controls whether you want to return only published entries 
    248              
     226 
    249227        startpoint = self.getStartpoint(context, fromHere) 
    250         # now we have the starting point for our search 
    251          
    252228        query=kwargs 
    253  
    254229        publishedState = self._getState() 
    255          
    256230        if category!=None: 
    257231            query['EntryCategory']=category 
    258232 
    259         #query['getAlwaysOnTop']=1 
    260          
    261233        if filterState: 
    262234            query['review_state']=publishedState             
    263235 
    264              
    265         #resultsTop = startpoint.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.getObjectPath(startpoint),'level':0}, sort_order='reverse', sort_on='effective') 
    266          
    267         #query['getAlwaysOnTop']=0 
    268236        results = startpoint.portal_catalog.searchResults(query, meta_type='BlogEntry',  
    269237                  path={'query':self.getObjectPath(startpoint),'level':0}, sort_order='reverse',  
    270238                  sort_on='effective', sort_limit=maxResults and maxResults or None) 
    271          
     239 
    272240        if  maxResults==0: 
    273241            return results 
     
    296264            onTop.sort((lambda x,y:cmp(y.effective(), x.effective()))) 
    297265            atBottom.sort((lambda x,y:cmp(y.effective(), x.effective()))) 
    298      
     266 
    299267            results = onTop+atBottom 
    300268        else: 
    301269            results = context.getEntries(category=category, maxResults=maxResults, filterState = filterState, sort=0, join=1, skipOnTop=1, **kwargs) 
    302              
    303270 
    304271        if maxResults==0: 
     
    377344                    lst.append(states[s].id) 
    378345        return lst 
    379      
     346 
    380347    security.declareProtected(CMFCorePermissions.ManagePortal,'getEntryWorkflowStates') 
    381348    def getEntryWorkflowStates(self, context): 
     
    387354                if not states[s].id in lst: 
    388355                    lst.append(states[s].id) 
    389          
     356 
    390357        return lst 
    391358 
     
    393360    def getObjectPath(self, object): 
    394361        return os.path.join(*object.getPhysicalPath()).replace('\\', '/') 
    395          
     362 
    396363    # ====================================================== 
    397364    # calendar stuff, copied from CMFCalender 
     
    412379        """ Returns a list of days with the correct start day first """         
    413380        return calendar.weekheader(2).split() 
    414          
     381 
    415382    security.declarePublic('getWeeksList') 
    416383    def getWeeksList(self, month='1', year='2002'): 
     
    425392        #  [28, 29, 30, 31, 0, 0, 0]] 
    426393        daysByWeek=calendar.monthcalendar(year, month) 
    427      
     394 
    428395        return daysByWeek 
    429396 
     
    443410        daysByWeek=calendar.monthcalendar(year, month) 
    444411        weeks=[] 
    445          
     412 
    446413        events=self.catalog_getevents(context, year, month) 
    447      
     414 
    448415        for week in daysByWeek: 
    449416            days=[] 
     
    453420                else: 
    454421                    days.append({'day': day, 'event': 0, 'eventslist':[]}) 
    455                  
     422 
    456423            weeks.append(days) 
    457              
     424 
    458425        return weeks 
    459      
     426 
    460427    security.declarePublic('catalog_getevents') 
    461428    def catalog_getevents(self, context, year, month): 
     
    467434        ## last_date=DateTime(str(month)+'/'+str(last_day)+'/'+str(year)) 
    468435        last_date=first_date + last_day     
    469          
     436 
    470437        # get the starting point for our search. This is where we depart from the standard catalog_tool: 
    471438        startpoint = self.getStartpoint(context, fromHere=0) 
    472          
     439 
    473440        query=self.portal_catalog(portal_type=self.calendar_types, 
    474441                              review_state=self._getState(), 
     
    479446                              path={'query':self.getObjectPath(startpoint),'level':0}, 
    480447                              sort_on='start') 
    481          
     448 
    482449        # compile a list of the days that have events 
    483450        eventDays={} 
     
    529496        # end calendar stuff 
    530497        # ================== 
    531      
    532      
    533      
     498 
    534499InitializeClass(SimpleBlogManager) 
  • SimpleBlog/branches/optimizations/content/blog.py

    r838 r841  
    198198                           condition="python:%s" % ENABLE_ADSENSE)), 
    199199        )) 
    200  
    201 # hide relatedItems 
    202200schema['relatedItems'].widget.visible={'view' : 'invisible', 'edit':'invisible'} 
    203201 
     
    225223        RPCAuth = self.simpleblog_tool.findRPCAuth(self) 
    226224 
    227         # Setup the MetaWeblog API 
    228225        self.metaWeblog = MetaWeblogAPI.MetaWeblogAPI().__of__(self) 
    229226        self.metaWeblog.setupRPCAuth(RPCAuth) 
    230  
    231         # Setup the Blogger API 
    232227        self.blogger = BloggerAPI.BloggerAPI().__of__(self) 
    233228        self.blogger.setupRPCAuth(RPCAuth) 
    234  
    235         # Setup the MovableTypeAPI API 
    236229        self.mt = MovableTypeAPI.MovableTypeAPI().__of__(self) 
    237230        self.mt.setupRPCAuth(RPCAuth)     
     
    247240 
    248241    def synContentValues(self): 
    249         # get brains for items that are published within the context of this blog. 
    250242        syn_tool = getToolByName(self, 'portal_syndication') 
    251243        limit = int(syn_tool.getMaxItems(self)) 
    252244        entries = self.getEntries(self, maxResults=limit) 
    253           
    254         # convert to objects 
    255245        objs = [e.getObject() for e in entries] 
    256246        return objs 
     
    259249        cats=self.getCategories() 
    260250 
    261         # add the global categories 
    262251        for c in self.simpleblog_tool.getGlobalCategories(): 
    263252            if not c in cats: 
     
    273262    def getEntries(self, category=None, maxResults=None, b_start=0, filterState=1, join=0, skipOnTop=0, mode="", **kwargs): 
    274263        """ Return all the contained published entries, real objects, not the brains """ 
    275         # see simpleblog_tool.searchForEntries for API description 
    276264        query=kwargs 
    277265        publishedState = self.simpleblog_tool.getPublishedState() 
     
    288276        query['meta_type'] = 'BlogEntry' 
    289277        onTop = [] 
    290         if not skipOnTop and b_start==0: #??? if number of marked with 'alwaysOnTop' BE > 'displayItems' -> they will present on second page 
     278        if not skipOnTop and b_start==0: 
    291279            query['getAlwaysOnTop']=1 
    292280            onTop = list(self.portal_catalog.searchResults(query)) 
     
    311299                    last = 1 
    312300                results = results[b_start:] 
    313             #if maxResults==0: 
    314             #    return (results,last) 
    315             #elif maxResults==None: 
    316             #    #results =[r.getObject() for r in  results[:self.simpleblog_tool.getMaxItemsInPortlet()]] 
    317             #    return (results,0) 
    318             #else: 
    319             #    results = [r.getObject() for r in results] 
    320             #    return (results,last) 
    321301            if mode == "full": 
    322302                results = (results,last) 
  • SimpleBlog/branches/optimizations/content/blogentry.py

    r695 r841  
    124124     )) 
    125125 
    126 # Finalise the schema according to ATContentTypes standards. This basically 
    127 # moves the Related items and Allow discussion fields to the bottom of the 
    128 # form. See ATContentTypes.content.schemata for details. 
    129126finalizeATCTSchema(schema) 
    130  
    131127 
    132128class BlogEntry(parentClass): 
     
    134130    A BlogEntry can exist inside a SimpleBlog Folder or an EntryFolder 
    135131    """ 
    136     # Standard content type setup 
    137132    portal_type = meta_type = 'BlogEntry' 
    138133    archetype_name = 'Blog Entry' 
     
    145140    immediate_view = 'blogentry_view' 
    146141 
    147     # Make sure we get title-to-id generation when an object is created 
    148142    _at_rename_after_creation = True 
    149143 
    150144    if ENTRY_IS_FOLDERISH: 
    151145        filter_content_types=1 
    152         allowed_content_types=('TrackBack') #('Link', 'Image', 'File', 'TrackBack') 
    153  
     146        allowed_content_types=('TrackBack') 
    154147 
    155148    def canSetDefaultPage(self): 
    156149        return False 
    157  
    158150 
    159151    def getAlwaysOnTop(self): 
     
    165157        else: 
    166158            return 0 
    167              
     159 
    168160    def getIcon(self, relative_to_portal=0): 
    169161        try: 
     
    174166        except: 
    175167            return 'entry_icon.gif' 
    176          
     168 
    177169    def listCategories(self): 
    178         # traverse upwards in the tree to collect all the available categories 
    179         # stop collecting when a SimpleBlog object is reached 
    180          
     170        """ Traverse upwards in the tree to collect all the available categories.""" 
    181171        cats=[] 
    182172        parent=self.aq_parent 
    183173        portal=self.portal_url.getPortalObject() 
    184          
     174 
    185175        while parent!=portal: 
    186176           if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder': 
    187                # add cats 
    188177               pcats=parent.getCategories() 
    189178               for c in pcats: 
     
    193182                   break 
    194183           parent=parent.aq_parent 
    195             
    196         # add the global categories 
     184 
    197185        for c in self.simpleblog_tool.getGlobalCategories(): 
    198186            if not c in cats: 
    199                 cats.append(c)            
     187                cats.append(c) 
    200188        cats.sort() 
    201189        return tuple(cats) 
     
    203191    def start(self): 
    204192        return self.getEffectiveDate() 
    205          
     193 
    206194    def end(self): 
    207         """  
    208         return the same data as start() since an entry is not an event but an item that is published on a specific 
    209         date. We want the entries in the calendar to appear on only one day. 
     195        """ Return the same data as start() since an entry is not an event but an item that is 
     196            published on a specific date. We want the entries in the calendar to appear on only one day. 
    210197        """ 
    211198        return self.getEffectiveDate() 
    212199 
    213  
    214  
    215  
    216 # ============================= 
    217  
    218     #function for sending ping 
    219200    def sendTrackBack(self): 
    220201        message = "TrackBack sent" 
     
    241222 
    242223    def getTrackbacks(self): 
    243         """ """ 
    244224        return self.listFolderContents(spec="TrackBack") 
    245225 
     
    276256 
    277257    def getBody(self): 
    278        return self.getField('body').get(self) 
     258        return self.getField('body').get(self) 
    279259 
    280260registerType(BlogEntry) 
  • SimpleBlog/branches/optimizations/content/blogfolder.py

    r838 r841  
    5858     
    5959    def getInheritedCategories(self): 
    60             # traverse upwards in the tree to collect all the available categories 
    61             # stop collecting when a SimpleBlog object is reached 
    62              
    63             cats=[] 
    64             parent=self.aq_parent 
    65             portal=self.portal_url.getPortalObject() 
    66             categories='<ul>' 
    67             while parent!=portal: 
    68                if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder': 
    69                    # add cats 
    70                    pcats=parent.getCategories() 
    71                    for c in pcats: 
    72                        if c not in cats: 
    73                            categories=categories + '<li>' + c + '</li>' 
    74                            cats.append(c) 
    75                    if parent.portal_type=='Blog': 
    76                        break 
    77                parent=parent.aq_parent 
    78             categories = categories + '</li>' 
    79             if len(cats)==0: 
    80                 return '-' 
    81             else: 
    82                 return categories 
     60        """ Traverse upwards in the tree to collect all the available categories.""" 
     61        cats=[] 
     62        parent=self.aq_parent 
     63        portal=self.portal_url.getPortalObject() 
     64        categories='<ul>' 
     65        while parent!=portal: 
     66            if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder': 
     67                # add cats 
     68                pcats=parent.getCategories() 
     69                for c in pcats: 
     70                    if c not in cats: 
     71                        categories=categories + '<li>' + c + '</li>' 
     72                        cats.append(c) 
     73                if parent.portal_type=='Blog': 
     74                    break 
     75            parent=parent.aq_parent 
     76        categories = categories + '</li>' 
     77        if len(cats)==0: 
     78            return '-' 
     79        else: 
     80            return categories 
    8381 
    8482    def getEntries(self, maxResults=None, **kwargs): 
    8583        """ Return all the contained published entries, real objects, not the brains """ 
    86         # see simpleblog_tool.searchForEntries for API description 
    87         #publishedState = self.simpleblog_tool.getPublishedState() 
    88          
    89         #query['getAlwaysOnTop']=1 
    90          
    91         ## first the items that need to be listed on top 
    92         #localOnTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') 
    93         #localOnTop = [r.getObject() for r in localOnTop ] 
    94          
    95         ## then the other items 
    96         #query['getAlwaysOnTop']=0 
    97         #localNoTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') 
    98         #localNoTop= [r.getObject() for r in localNoTop]         
    99          
    100         #results = localOnTop+localNoTop 
    101          
    102         #if maxResults==0: 
    103             #return results 
    104         #elif maxResults==None: 
    105             #return results[:self.simpleblog_tool.getMaxItemsInPortlet()] 
    106         #else: 
    107             #return results[:maxResults]                
    10884        blog = self.simpleblog_tool.getFrontPage(self) 
    10985        kwargs.update({'path':{'query':'/'+'/'.join(self.getPhysicalPath()),'level':0}}) 
    11086        return blog.getEntries(maxResults=maxResults, **kwargs) 
    11187 
    112      
     88 
    11389    def synContentValues(self): 
    114         # get brains for items that are published within the context of this blog. 
    11590        entries = self.simpleblog_tool.searchForEntries(self, fromHere=1, maxResults=0) 
    116          
    117         # convert to objects 
    11891        objs = [e.getObject() for e in entries] 
    119         return objs         
    120                  
     92        return objs 
     93 
    12194registerType(BlogFolder)