Changeset 841
- Timestamp:
- 04/11/07 05:20:09
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
SimpleBlog/branches/optimizations/SimpleBlogTool.py
r838 r841 18 18 meta_type= 'SimpleBlog manager' 19 19 plone_tool = 1 20 20 21 21 manage_options=PropertyManager.manage_options 22 22 23 23 security = ClassSecurityInfo() 24 24 calendar_types=['BlogEntry'] 25 25 use_session="" 26 26 27 27 def __init__(self): 28 28 self.manage_addProperty('publishedState', 'published', 'string') … … 76 76 except: 77 77 return [] 78 78 79 79 def _getCreatePortletOnBlogCreation(self): 80 80 try: … … 100 100 101 101 self.globalCategories=value 102 102 103 103 security.declarePublic('getPublishedState') 104 104 def getPublishedState(self): 105 105 return self._getState() 106 107 106 108 107 security.declarePublic('getMaxItemsInPortlet') 109 108 def getMaxItemsInPortlet(self): 110 109 return self._getMaxItemsInPortlet() 111 110 112 111 security.declarePublic('getFrontPage') 113 112 def getFrontPage(self, context): … … 127 126 break 128 127 parent=parent.aq_parent 129 128 130 129 if found==1: 131 130 return parent … … 142 141 """ 143 142 plone_utils = getToolByName(context, 'plone_utils') 144 143 145 144 startpoint = self.getFrontPage(context) 146 145 if not startpoint: … … 152 151 else: 153 152 return startpoint 154 153 155 154 security.declarePublic('getAvailableCategories') 156 155 def getAvailableCategories(self, context, startpoint=None): … … 162 161 # if we are higher in the tree than any Blog then we will end up in the portalobject itself 163 162 # in that case we just search for categories starting in context. 164 165 166 163 if not startpoint: 167 164 startpoint = self.getStartpoint(context, fromHere=0) … … 169 166 path = self.getObjectPath(startpoint) 170 167 171 # now we have the starting point for our search172 173 #result = startpoint.portal_catalog.searchResults(meta_type=['BlogFolder', 'Blog'], path={'query':self.getObjectPath(startpoint),'level':0})174 175 # now fetch all the available categories176 #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 categories185 #for c in self.getGlobalCategories():186 # if not c in categories:187 # categories.append(c)188 189 168 # now we have a list of unique categories available from startpoint and deeper in tree 190 169 # next step is to count the number of entries for each category … … 196 175 rescats[c]=len(result) 197 176 return rescats 198 #return categories 199 177 200 178 security.declarePublic('getSortedKeys') 201 179 def getSortedKeys(self, dict): … … 203 181 keys.sort() 204 182 return keys 205 183 206 184 security.declarePublic('getGlobalCategories') 207 185 def getGlobalCategories(self): 208 186 return self._getGlobalCategories() 209 187 210 188 security.declarePublic('getStartpoint') 211 189 def getStartpoint(self, context, fromHere=0): … … 222 200 break 223 201 parent=parent.aq_parent 224 202 225 203 if found==1: 226 204 startpoint=parent … … 234 212 235 213 return startpoint 236 214 237 215 security.declarePublic('searchForEntries') 238 216 def searchForEntries(self, context, category=None, maxResults=None, fromHere=0, filterState=1, **kwargs): … … 240 218 # leave it to None to get the max from the properties 241 219 # set fromHere=1 to search from the current location. Is used for BlogFolders 242 220 243 221 # first, get the context right 244 222 # when inside a Blog: search for the frontpage 245 223 # when outside a Blog: use context (or its container) 246 224 247 225 #filterState controls whether you want to return only published entries 248 226 249 227 startpoint = self.getStartpoint(context, fromHere) 250 # now we have the starting point for our search251 252 228 query=kwargs 253 254 229 publishedState = self._getState() 255 256 230 if category!=None: 257 231 query['EntryCategory']=category 258 232 259 #query['getAlwaysOnTop']=1260 261 233 if filterState: 262 234 query['review_state']=publishedState 263 235 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']=0268 236 results = startpoint.portal_catalog.searchResults(query, meta_type='BlogEntry', 269 237 path={'query':self.getObjectPath(startpoint),'level':0}, sort_order='reverse', 270 238 sort_on='effective', sort_limit=maxResults and maxResults or None) 271 239 272 240 if maxResults==0: 273 241 return results … … 296 264 onTop.sort((lambda x,y:cmp(y.effective(), x.effective()))) 297 265 atBottom.sort((lambda x,y:cmp(y.effective(), x.effective()))) 298 266 299 267 results = onTop+atBottom 300 268 else: 301 269 results = context.getEntries(category=category, maxResults=maxResults, filterState = filterState, sort=0, join=1, skipOnTop=1, **kwargs) 302 303 270 304 271 if maxResults==0: … … 377 344 lst.append(states[s].id) 378 345 return lst 379 346 380 347 security.declareProtected(CMFCorePermissions.ManagePortal,'getEntryWorkflowStates') 381 348 def getEntryWorkflowStates(self, context): … … 387 354 if not states[s].id in lst: 388 355 lst.append(states[s].id) 389 356 390 357 return lst 391 358 … … 393 360 def getObjectPath(self, object): 394 361 return os.path.join(*object.getPhysicalPath()).replace('\\', '/') 395 362 396 363 # ====================================================== 397 364 # calendar stuff, copied from CMFCalender … … 412 379 """ Returns a list of days with the correct start day first """ 413 380 return calendar.weekheader(2).split() 414 381 415 382 security.declarePublic('getWeeksList') 416 383 def getWeeksList(self, month='1', year='2002'): … … 425 392 # [28, 29, 30, 31, 0, 0, 0]] 426 393 daysByWeek=calendar.monthcalendar(year, month) 427 394 428 395 return daysByWeek 429 396 … … 443 410 daysByWeek=calendar.monthcalendar(year, month) 444 411 weeks=[] 445 412 446 413 events=self.catalog_getevents(context, year, month) 447 414 448 415 for week in daysByWeek: 449 416 days=[] … … 453 420 else: 454 421 days.append({'day': day, 'event': 0, 'eventslist':[]}) 455 422 456 423 weeks.append(days) 457 424 458 425 return weeks 459 426 460 427 security.declarePublic('catalog_getevents') 461 428 def catalog_getevents(self, context, year, month): … … 467 434 ## last_date=DateTime(str(month)+'/'+str(last_day)+'/'+str(year)) 468 435 last_date=first_date + last_day 469 436 470 437 # get the starting point for our search. This is where we depart from the standard catalog_tool: 471 438 startpoint = self.getStartpoint(context, fromHere=0) 472 439 473 440 query=self.portal_catalog(portal_type=self.calendar_types, 474 441 review_state=self._getState(), … … 479 446 path={'query':self.getObjectPath(startpoint),'level':0}, 480 447 sort_on='start') 481 448 482 449 # compile a list of the days that have events 483 450 eventDays={} … … 529 496 # end calendar stuff 530 497 # ================== 531 532 533 498 534 499 InitializeClass(SimpleBlogManager) SimpleBlog/branches/optimizations/content/blog.py
r838 r841 198 198 condition="python:%s" % ENABLE_ADSENSE)), 199 199 )) 200 201 # hide relatedItems202 200 schema['relatedItems'].widget.visible={'view' : 'invisible', 'edit':'invisible'} 203 201 … … 225 223 RPCAuth = self.simpleblog_tool.findRPCAuth(self) 226 224 227 # Setup the MetaWeblog API228 225 self.metaWeblog = MetaWeblogAPI.MetaWeblogAPI().__of__(self) 229 226 self.metaWeblog.setupRPCAuth(RPCAuth) 230 231 # Setup the Blogger API232 227 self.blogger = BloggerAPI.BloggerAPI().__of__(self) 233 228 self.blogger.setupRPCAuth(RPCAuth) 234 235 # Setup the MovableTypeAPI API236 229 self.mt = MovableTypeAPI.MovableTypeAPI().__of__(self) 237 230 self.mt.setupRPCAuth(RPCAuth) … … 247 240 248 241 def synContentValues(self): 249 # get brains for items that are published within the context of this blog.250 242 syn_tool = getToolByName(self, 'portal_syndication') 251 243 limit = int(syn_tool.getMaxItems(self)) 252 244 entries = self.getEntries(self, maxResults=limit) 253 254 # convert to objects255 245 objs = [e.getObject() for e in entries] 256 246 return objs … … 259 249 cats=self.getCategories() 260 250 261 # add the global categories262 251 for c in self.simpleblog_tool.getGlobalCategories(): 263 252 if not c in cats: … … 273 262 def getEntries(self, category=None, maxResults=None, b_start=0, filterState=1, join=0, skipOnTop=0, mode="", **kwargs): 274 263 """ Return all the contained published entries, real objects, not the brains """ 275 # see simpleblog_tool.searchForEntries for API description276 264 query=kwargs 277 265 publishedState = self.simpleblog_tool.getPublishedState() … … 288 276 query['meta_type'] = 'BlogEntry' 289 277 onTop = [] 290 if not skipOnTop and b_start==0: #??? if number of marked with 'alwaysOnTop' BE > 'displayItems' -> they will present on second page278 if not skipOnTop and b_start==0: 291 279 query['getAlwaysOnTop']=1 292 280 onTop = list(self.portal_catalog.searchResults(query)) … … 311 299 last = 1 312 300 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)321 301 if mode == "full": 322 302 results = (results,last) SimpleBlog/branches/optimizations/content/blogentry.py
r695 r841 124 124 )) 125 125 126 # Finalise the schema according to ATContentTypes standards. This basically127 # moves the Related items and Allow discussion fields to the bottom of the128 # form. See ATContentTypes.content.schemata for details.129 126 finalizeATCTSchema(schema) 130 131 127 132 128 class BlogEntry(parentClass): … … 134 130 A BlogEntry can exist inside a SimpleBlog Folder or an EntryFolder 135 131 """ 136 # Standard content type setup137 132 portal_type = meta_type = 'BlogEntry' 138 133 archetype_name = 'Blog Entry' … … 145 140 immediate_view = 'blogentry_view' 146 141 147 # Make sure we get title-to-id generation when an object is created148 142 _at_rename_after_creation = True 149 143 150 144 if ENTRY_IS_FOLDERISH: 151 145 filter_content_types=1 152 allowed_content_types=('TrackBack') #('Link', 'Image', 'File', 'TrackBack') 153 146 allowed_content_types=('TrackBack') 154 147 155 148 def canSetDefaultPage(self): 156 149 return False 157 158 150 159 151 def getAlwaysOnTop(self): … … 165 157 else: 166 158 return 0 167 159 168 160 def getIcon(self, relative_to_portal=0): 169 161 try: … … 174 166 except: 175 167 return 'entry_icon.gif' 176 168 177 169 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.""" 181 171 cats=[] 182 172 parent=self.aq_parent 183 173 portal=self.portal_url.getPortalObject() 184 174 185 175 while parent!=portal: 186 176 if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder': 187 # add cats188 177 pcats=parent.getCategories() 189 178 for c in pcats: … … 193 182 break 194 183 parent=parent.aq_parent 195 196 # add the global categories 184 197 185 for c in self.simpleblog_tool.getGlobalCategories(): 198 186 if not c in cats: 199 cats.append(c) 187 cats.append(c) 200 188 cats.sort() 201 189 return tuple(cats) … … 203 191 def start(self): 204 192 return self.getEffectiveDate() 205 193 206 194 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. 210 197 """ 211 198 return self.getEffectiveDate() 212 199 213 214 215 216 # =============================217 218 #function for sending ping219 200 def sendTrackBack(self): 220 201 message = "TrackBack sent" … … 241 222 242 223 def getTrackbacks(self): 243 """ """244 224 return self.listFolderContents(spec="TrackBack") 245 225 … … 276 256 277 257 def getBody(self): 278 return self.getField('body').get(self)258 return self.getField('body').get(self) 279 259 280 260 registerType(BlogEntry) SimpleBlog/branches/optimizations/content/blogfolder.py
r838 r841 58 58 59 59 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 83 81 84 82 def getEntries(self, maxResults=None, **kwargs): 85 83 """ Return all the contained published entries, real objects, not the brains """ 86 # see simpleblog_tool.searchForEntries for API description87 #publishedState = self.simpleblog_tool.getPublishedState()88 89 #query['getAlwaysOnTop']=190 91 ## first the items that need to be listed on top92 #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 items96 #query['getAlwaysOnTop']=097 #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+localNoTop101 102 #if maxResults==0:103 #return results104 #elif maxResults==None:105 #return results[:self.simpleblog_tool.getMaxItemsInPortlet()]106 #else:107 #return results[:maxResults]108 84 blog = self.simpleblog_tool.getFrontPage(self) 109 85 kwargs.update({'path':{'query':'/'+'/'.join(self.getPhysicalPath()),'level':0}}) 110 86 return blog.getEntries(maxResults=maxResults, **kwargs) 111 87 112 88 113 89 def synContentValues(self): 114 # get brains for items that are published within the context of this blog.115 90 entries = self.simpleblog_tool.searchForEntries(self, fromHere=1, maxResults=0) 116 117 # convert to objects118 91 objs = [e.getObject() for e in entries] 119 return objs 120 92 return objs 93 121 94 registerType(BlogFolder)
