Changeset 579
- Timestamp:
- 10/19/06 08:59:57
- Files:
-
- SimpleBlog/branches/plone-2.5/content/blog.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
SimpleBlog/branches/plone-2.5/content/blog.py
r578 r579 8 8 import Products.SimpleBlog.Permissions 9 9 from Products.CMFCore.utils import getToolByName 10 11 import MetaWeblogAPI 12 import BloggerAPI 13 import MovableTypeAPI 10 14 11 15 from Products.ATContentTypes.content.base import ATCTFolder … … 38 42 description='Set the maximum number of BlogEntries to display.'), 39 43 default=20), 44 LinesField('categories', 45 widget=LinesWidget(label='Possible Categories', 46 label_msgid="label_categories", 47 description_msgid="help_categories", 48 i18n_domain="SimpleBlog", 49 description='Supply the list of possible categories that can be used in SimpleBlog Entries.')), 40 50 BooleanField('warnForUnpublishedEntries', 41 51 default=1, … … 45 55 description_msgid="help_warnForUnpublishedEntries", 46 56 description='When checked, a warning will be displayed on the blog\'s frontpage if there are entries that are not yet published.')), 47 BooleanField('allowCrossPosting', 57 BooleanField('allowCrossPosting', 48 58 default=0, 49 widget=BooleanWidget(condition="python:0", # this line have to be removed in order to be visible/editable50 label='Allow cross-posting', 59 widget=BooleanWidget(condition="python:0", # hide the field 60 label='Allow cross-posting', 51 61 i18n_domain="SimpleBlog", 52 62 label_msgid="label_allowCrossPosting", 53 63 description_msgid="help_allowCrossPosting", 54 64 description='When checked, this blog will include cross-post entries from other blogs.')), 55 LinesField('categories', 56 widget=LinesWidget(label='Possible Categories', 57 label_msgid="label_categories", 58 description_msgid="help_categories", 59 i18n_domain="SimpleBlog", 60 description='Supply the list of possible categories that can be used in SimpleBlog Entries.')), 65 LinesField('tags', 66 mutator = 'setTags', 67 widget=LinesWidget(label="Tags", 68 description='List of tags.'), 69 ), 70 BooleanField('tagsEnabled', 71 accessor = 'isTagsEnabled', 72 default = 1, 73 schemata = 'interface', 74 widget = BooleanWidget(label='Enable technorati tags', 75 label_msgid="label_enable_tags", 76 description_msgid="help_enable_tags",), 77 ), 61 78 BooleanField('allowTrackback', 62 79 default = 1, … … 76 93 description_msgid="help_adminEmail", 77 94 i18n_domain="SimpleBlog", 78 condition="python:0", # this line have to be removed in order to be visible/editable79 description="Enter administrator's email for rece aving notification about blog's activity"),95 condition="python:0", # this line have to be removed in order to be visible/editable 96 description="Enter administrator's email for receiving notification about blog's activity"), 80 97 ), 81 98 BooleanField('allowDelicious', 99 default = 1, 100 accessor = 'isDeliciousEnabled', 101 schemata = 'interface', 102 widget=BooleanWidget(label="Turn Delicious bookmarklet", 103 label_msgid="label_allow_delicious", 104 description_msgid="help_allow_delicious"), 105 ), 106 BooleanField('allowDigg', 107 default = 1, 108 accessor = 'isDiggEnabled', 109 schemata = 'interface', 110 widget=BooleanWidget(label="Turn Digg bookmarklet", 111 label_msgid="label_allow_digg", 112 description_msgid="help_allow_digg"), 113 ), 114 BooleanField('allowYahoo', 115 default = 1, 116 accessor = 'isYahooEnabled', 117 schemata = 'interface', 118 widget=BooleanWidget(label="Turn Yahoo bookmarklet", 119 label_msgid="label_allow_yahoo", 120 description_msgid="help_allow_yahoo"), 121 ), 122 BooleanField('allowGoogle', 123 default = 1, 124 accessor = 'isGoogleEnabled', 125 schemata = 'interface', 126 widget=BooleanWidget(label="Turn Google bookmarklet", 127 label_msgid="label_allow_google", 128 description_msgid="help_allow_google"), 129 ), 130 BooleanField('allowSpurl', 131 default = 1, 132 accessor = 'isSpurlEnabled', 133 schemata = 'interface', 134 widget=BooleanWidget(label="Turn Spurl bookmarklet", 135 label_msgid="label_allow_spurl", 136 description_msgid="help_allow_spurl"), 137 ), 82 138 )) 83 139 … … 93 149 schema = schema 94 150 global_allow=1 95 151 96 152 default_view = 'simpleblog_view_title_description' 97 153 immediate_view = 'simpleblog_view_title_description' … … 101 157 allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet') 102 158 159 blogger = None 160 metaWeblog = None 161 162 def initializeArchetype(self, **kwargs): 163 BaseFolder.initializeArchetype(self, **kwargs) 164 RPCAuth = self.simpleblog_tool.findRPCAuth(self) 165 166 # Setup the MetaWeblog API 167 self.metaWeblog = MetaWeblogAPI.MetaWeblogAPI().__of__(self) 168 self.metaWeblog.setupRPCAuth(RPCAuth) 169 170 # Setup the Blogger API 171 self.blogger = BloggerAPI.BloggerAPI().__of__(self) 172 self.blogger.setupRPCAuth(RPCAuth) 173 174 # Setup the MovableTypeAPI API 175 self.mt = MovableTypeAPI.MovableTypeAPI().__of__(self) 176 self.mt.setupRPCAuth(RPCAuth) 177 103 178 def canSetDefaultPage(self): 104 179 return False 105 106 180 107 181 def manage_afterAdd(self, item, container): … … 114 188 # get brains for items that are published within the context of this blog. 115 189 entries = self.simpleblog_tool.searchForEntries(self, maxResults=0) 116 190 117 191 # convert to objects 118 192 objs = [e.getObject() for e in entries] 119 193 return objs 120 194 121 195 def listCategories(self): 122 196 cats=self.getCategories() 123 197 124 198 # add the global categories 125 199 for c in self.simpleblog_tool.getGlobalCategories(): 126 200 if not c in cats: 127 cats.append(c) 201 cats.append(c) 128 202 cats = list(cats) 129 203 cats.sort() 130 return tuple(cats) 204 return tuple(cats) 131 205 132 206 def getForeignEntries(self): … … 134 208 return [f for f in self.getBRefs('AppearsIn') if self.portal_membership.checkPermission('View', f)] 135 209 136 137 210 def getEntries(self, category=None, maxResults=None, fromHere=0, filterState=1, sort=1, join=0, addCrossPostInfo=0, **kwargs): 138 211 """ Return all the contained published entries, real objects, not the brains """ 139 212 # see simpleblog_tool.searchForEntries for API description 140 141 213 query=kwargs 142 143 214 publishedState = self.simpleblog_tool.getPublishedState() 144 145 215 if category!=None: 146 216 query['EntryCategory']=category 147 148 217 query['getAlwaysOnTop']=1 149 150 218 if filterState: 151 219 query['review_state']=publishedState 152 153 220 # first the items that need to be listed on top 154 221 localOnTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') 155 222 localOnTop = [r.getObject() for r in localOnTop ] 156 157 223 # then the other items 158 224 query['getAlwaysOnTop']=0 159 225 localNoTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') 160 226 localNoTop= [r.getObject() for r in localNoTop] 161 227 162 228 # foreign items 163 229 if self.getAllowCrossPosting(): … … 169 235 foreignOnTop = [e for e in foreignEntries if e.getAlwaysOnTop()] 170 236 foreignNoTop = [e for e in foreignEntries if not e.getAlwaysOnTop()] 171 172 237 # so, now we have: 173 238 # total = localOnTop + foreignOnTop + localNoTop + foreignNoTop 174 239 # and that needs to be sorted 175 176 177 240 if addCrossPostInfo: 178 241 # make each object a tuple (obj, <iscrosspost>) … … 181 244 localOnTop = [(e,0) for e in localOnTop] 182 245 localNoTop = [(e,0) for e in localNoTop] 183 184 246 onTop = foreignOnTop + localOnTop 185 247 onBottom = foreignNoTop + localNoTop 186 187 248 if sort and foreignEntries: 188 249 if addCrossPostInfo: … … 192 253 onTop.sort((lambda x,y:cmp(y.effective(), x.effective()))) 193 254 onBottom.sort((lambda x,y:cmp(y.effective(), x.effective()))) 194 195 255 if join: 196 256 results = onTop+onBottom … … 200 260 return results[:self.simpleblog_tool.getMaxItemsInPortlet()] 201 261 else: 202 return results[:maxResults] 262 return results[:maxResults] 203 263 else: 204 264 return (onTop, onBottom) 205 265 206 266 def getAdminEmail(self): 207 267 """ return blog admin email or root email """ … … 212 272 return val 213 273 274 def setTags(self, value, **kwargs): 275 """ Save tags in lower case """ 276 value = unique(value) 277 value.sort(lambda x, y: cmp(x,y)) 278 self.getField('tags').set(self, value, **kwargs) 279 214 280 registerType(Blog) 215 281
