[1] | 1 | from Products.Archetypes.public import * |
---|
| 2 | |
---|
| 3 | #from Products.Archetypes.public import BaseSchema, BaseFolderSchema, Schema |
---|
| 4 | #from Products.Archetypes.public import StringField, TextField, LinesField, BooleanField |
---|
| 5 | #from Products.Archetypes.public import TextAreaWidget, VisualWidget, MultiSelectionWidget, StringWidget, IdWidget |
---|
| 6 | #from Products.Archetypes.public import RichWidget, BooleanWidget |
---|
| 7 | #from Products.Archetypes.public import BaseContent, registerType, BaseFolder |
---|
| 8 | from Products.CMFCore import CMFCorePermissions |
---|
| 9 | |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | |
---|
| 12 | from DateTime import DateTime |
---|
| 13 | |
---|
| 14 | import Permissions |
---|
| 15 | import string,os,urllib,httplib,urlparse,re |
---|
| 16 | import sys |
---|
| 17 | from util import * |
---|
| 18 | from config import DIGG_TOPICS |
---|
| 19 | |
---|
| 20 | schema = BaseFolderSchema + Schema(( |
---|
| 21 | StringField('id', |
---|
| 22 | required = 0, ## Still actually required, but |
---|
| 23 | ## the widget will supply the missing value |
---|
| 24 | ## on non-submits |
---|
| 25 | mode = "rw", |
---|
| 26 | accessor = "getId", |
---|
| 27 | mutator = "setId", |
---|
| 28 | default = None, |
---|
| 29 | widget = IdWidget(label = "Short Name", |
---|
| 30 | label_msgid = "label_short_name", |
---|
| 31 | description = "Should not contain spaces, underscores or mixed case. "\ |
---|
| 32 | "Short Name is part of the item's web address.", |
---|
| 33 | description_msgid = "help_shortname", |
---|
| 34 | visible = {'view' : 'visible', 'edit':'visible'}, |
---|
| 35 | i18n_domain = "plone"), |
---|
| 36 | ), |
---|
| 37 | StringField('title', |
---|
| 38 | required = 1, |
---|
| 39 | searchable = 1, |
---|
| 40 | default = '', |
---|
| 41 | accessor = 'Title', |
---|
| 42 | widget = StringWidget(label_msgid = "label_title", |
---|
| 43 | description_msgid = "help_title", |
---|
| 44 | i18n_domain = "plone"), |
---|
| 45 | ), |
---|
| 46 | StringField('description', |
---|
| 47 | searchable = 1, |
---|
| 48 | isMetadata = 1, |
---|
| 49 | accessor = 'Description', |
---|
| 50 | widget = TextAreaWidget(label = 'Description', |
---|
| 51 | label_msgid = "label_entry_description", |
---|
| 52 | description_msgid = "help_entry_description", |
---|
| 53 | i18n_domain = "SimpleBlog", |
---|
| 54 | raws = 3, |
---|
| 55 | description = 'Give a description for this entry.'),), |
---|
| 56 | TextField('body', |
---|
| 57 | searchable = 1, |
---|
| 58 | required = 0, |
---|
| 59 | primary = 1, |
---|
| 60 | default_content_type = 'text/html', |
---|
| 61 | default_output_type = 'text/html', |
---|
| 62 | allowable_content_types = ('text/plain','text/structured', 'text/html', 'text/restructured'), |
---|
| 63 | widget = RichWidget(label = 'Body', |
---|
| 64 | label_msgid = "label_entry_body", |
---|
| 65 | description_msgid = "help_entry_body", |
---|
| 66 | i18n_domain = "SimpleBlog", |
---|
| 67 | description = "Body of the blog")), |
---|
| 68 | |
---|
| 69 | LinesField('categories', |
---|
| 70 | accessor = 'EntryCategory', |
---|
| 71 | edit_accessor = 'EntryCategory', |
---|
| 72 | index = 'KeywordIndex', |
---|
| 73 | vocabulary = 'listCategories', |
---|
| 74 | widget = MultiSelectionWidget(format = 'select', |
---|
| 75 | label_msgid = "label_entry_categories", |
---|
| 76 | description_msgid = "help_entry_categories", |
---|
| 77 | i18n_domain = "SimpleBlog", |
---|
| 78 | label = 'Categories', |
---|
| 79 | description = 'Select to which categories this Entry belongs to')), |
---|
| 80 | LinesField('tags', |
---|
| 81 | accessor = 'EntryTag', |
---|
| 82 | mutator = 'setEntryTag', |
---|
| 83 | index = 'KeywordIndex', |
---|
| 84 | enforseVocabulary = 1, |
---|
| 85 | vocabulary = 'listTags', |
---|
| 86 | widget = KeywordWidget(label_msgid = "label_entry_tags", |
---|
| 87 | description_msgid = "help_entry_tags", |
---|
| 88 | i18n_domain = "SimpleBlog", |
---|
| 89 | label = 'Tags', |
---|
| 90 | description = 'Select tags for technorati.com')), |
---|
| 91 | |
---|
| 92 | BooleanField('alwaysOnTop', |
---|
| 93 | default = 0, |
---|
| 94 | index = 'FieldIndex:schema', |
---|
| 95 | widget = BooleanWidget(label = 'Entry is always listed on top.', |
---|
| 96 | label_msgid = "label_always_top", |
---|
| 97 | description_msgid = "help_always_top", |
---|
| 98 | i18n_domain = "SimpleBlog", |
---|
| 99 | description = 'Controls if the Entry (when published) shown as the first Entry. If not checked, the effective date is used.')), |
---|
| 100 | LinesField('sendTrackBackURLs', |
---|
| 101 | languageIndependent = True, |
---|
| 102 | searchable = True, |
---|
| 103 | widget = LinesWidget(label = "sendTrackBackURLs", |
---|
| 104 | label_msgid = "label_sendTrackBackURLs", |
---|
| 105 | description = ("URL for sending trackbacks"), |
---|
| 106 | description_msgid = "help_event_attendees", |
---|
| 107 | i18n_domain = "plone")), |
---|
| 108 | |
---|
| 109 | BooleanField('enableTopAdsence', |
---|
| 110 | widget = BooleanWidget(format = 'select', |
---|
| 111 | label_msgid = "label_enable_top_adsence", |
---|
| 112 | description_msgid = "help_enable_top_adsence", |
---|
| 113 | i18n_domain = "SimpleBlog", |
---|
| 114 | label = 'Enable top Adsence block', |
---|
| 115 | description = None)), |
---|
| 116 | StringField('topAdsence', |
---|
| 117 | vocabulary = 'listAdesnceTemplates', |
---|
| 118 | widget = SelectionWidget(format = 'select', |
---|
| 119 | label_msgid = "label_top_adsence", |
---|
| 120 | description_msgid = "help_top_adsence", |
---|
| 121 | i18n_domain = "SimpleBlog", |
---|
| 122 | label = 'Top Adsence', |
---|
| 123 | description = None)), |
---|
| 124 | BooleanField('enableBottomAdsence', |
---|
| 125 | widget = BooleanWidget(format = 'select', |
---|
| 126 | label_msgid = "label_enable_bottom_adsence", |
---|
| 127 | description_msgid = "help_enable_bottom_adsence", |
---|
| 128 | i18n_domain = "SimpleBlog", |
---|
| 129 | label = 'Enable bottom Adsence block', |
---|
| 130 | description = None)), |
---|
| 131 | StringField('bottomAdsence', |
---|
| 132 | vocabulary = 'listAdesnceTemplates', |
---|
| 133 | widget = SelectionWidget(format = 'select', |
---|
| 134 | label_msgid = "label_bottom_adsence", |
---|
| 135 | description_msgid = "help_bottom_adsence", |
---|
| 136 | i18n_domain = "SimpleBlog", |
---|
| 137 | label = 'Bottom Adsence', |
---|
| 138 | description = None)), |
---|
| 139 | StringField('diggTopic', |
---|
| 140 | default='offbeat_news', |
---|
| 141 | vocabulary=DIGG_TOPICS, |
---|
| 142 | widget=SelectionWidget(label='Digg topic', |
---|
| 143 | label_msgid="label_digg_topic", |
---|
| 144 | description_msgid="help_digg_topic", |
---|
| 145 | i18n_domain="SimpleBlog", |
---|
| 146 | description='Choose the digg topic.')), |
---|
| 147 | )) |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | class BlogEntry(BaseFolder): |
---|
| 151 | """ |
---|
| 152 | A BlogEntry can exist inside a SimpleBlog Folder or an EntryFolder |
---|
| 153 | """ |
---|
| 154 | |
---|
| 155 | schema = schema |
---|
| 156 | |
---|
| 157 | global_allow = 0 |
---|
| 158 | |
---|
| 159 | content_icon = 'entry_icon.gif' |
---|
| 160 | |
---|
| 161 | filter_content_types = 1 |
---|
| 162 | allowed_content_types = ('TrackBack','Link', 'Image', 'File') |
---|
| 163 | |
---|
| 164 | actions = ({ |
---|
| 165 | 'id': 'view', |
---|
| 166 | 'name': 'View', |
---|
| 167 | 'action': 'string:${object_url}/blogentry_view', |
---|
| 168 | 'permissions': (CMFCorePermissions.View,) |
---|
| 169 | }, |
---|
| 170 | {'id': 'references', |
---|
| 171 | 'name': 'References', |
---|
| 172 | 'action': 'string:${object_url}/reference_edit', |
---|
| 173 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
| 174 | 'visible':0}, |
---|
| 175 | {'id': 'metadata', |
---|
| 176 | 'name': 'Properties', |
---|
| 177 | 'action': 'string:${object_url}/base_metadata', |
---|
| 178 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
| 179 | 'visible':0}) |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | def getAlwaysOnTop(self): |
---|
| 185 | if hasattr(self, 'alwaysOnTop'): |
---|
| 186 | if self.alwaysOnTop == None or self.alwaysOnTop == 0: |
---|
| 187 | return 0 |
---|
| 188 | else: |
---|
| 189 | return 1 |
---|
| 190 | else: |
---|
| 191 | return 0 |
---|
| 192 | |
---|
| 193 | def getIcon(self, relative_to_portal = 0): |
---|
| 194 | try: |
---|
| 195 | if self.getAlwaysOnTop() == 0: |
---|
| 196 | return 'entry_icon.gif' |
---|
| 197 | else: |
---|
| 198 | return 'entry_pin.gif' |
---|
| 199 | except: |
---|
| 200 | return 'entry_icon.gif' |
---|
| 201 | |
---|
| 202 | def listCategories(self): |
---|
| 203 | # traverse upwards in the tree to collect all the available categories |
---|
| 204 | # stop collecting when a SimpleBlog object is reached |
---|
| 205 | |
---|
| 206 | cats = [] |
---|
| 207 | parent = self.aq_parent |
---|
| 208 | portal = self.portal_url.getPortalObject() |
---|
| 209 | |
---|
| 210 | while parent != portal: |
---|
| 211 | if parent.portal_type == 'Blog' or parent.portal_type == 'BlogFolder': |
---|
| 212 | # add cats |
---|
| 213 | pcats = parent.getCategories() |
---|
| 214 | for c in pcats: |
---|
| 215 | if c not in cats: |
---|
| 216 | cats.append(c) |
---|
| 217 | if parent.portal_type == 'Blog': |
---|
| 218 | break |
---|
| 219 | parent = parent.aq_parent |
---|
| 220 | |
---|
| 221 | # add the global categories |
---|
| 222 | for c in self.simpleblog_tool.getGlobalCategories(): |
---|
| 223 | if not c in cats: |
---|
| 224 | cats.append(c) |
---|
| 225 | cats.sort() |
---|
| 226 | return tuple(cats) |
---|
| 227 | |
---|
| 228 | def start(self): |
---|
| 229 | return self.getEffectiveDate() |
---|
| 230 | |
---|
| 231 | def end(self): |
---|
| 232 | """ |
---|
| 233 | return the same data as start() since an entry is not an event but an item that is published on a specific |
---|
| 234 | date. We want the entries in the calendar to appear on only one day. |
---|
| 235 | """ |
---|
| 236 | return self.getEffectiveDate() |
---|
| 237 | |
---|
| 238 | #function for sending ping |
---|
| 239 | def sendTrackBack(self): |
---|
| 240 | message = "TrackBack sent" |
---|
| 241 | title = self.title |
---|
| 242 | src_url = self.absolute_url() |
---|
| 243 | blog = self.simpleblog_tool.getFrontPage(self) |
---|
| 244 | blog_name = blog.Title() |
---|
| 245 | excerpt=self.description |
---|
| 246 | agent = "SimpleBlog" |
---|
| 247 | result=[] |
---|
| 248 | for i in self.getSendTrackBackURLs(): |
---|
| 249 | ping_url=i |
---|
| 250 | err,mes = post_trackback(self, |
---|
| 251 | ping_url=ping_url, |
---|
| 252 | title = title, |
---|
| 253 | src_url = src_url, |
---|
| 254 | blog_name = blog_name, |
---|
| 255 | excerpt=self.description, |
---|
| 256 | agent = "SimpleBlog", |
---|
| 257 | charset = "utf-8") |
---|
| 258 | result.append((err,mes)) |
---|
| 259 | result.append(("excerpt",self.description)) |
---|
| 260 | return result |
---|
| 261 | |
---|
| 262 | def getTrackbacks(self): |
---|
| 263 | """ """ |
---|
| 264 | return self.listFolderContents(spec="TrackBack") |
---|
| 265 | |
---|
| 266 | def setEntryTag(self, value, **kwargs): |
---|
| 267 | """ Update tags in the Entry in parent Blog """ |
---|
| 268 | value = list(value) |
---|
| 269 | value.sort() |
---|
| 270 | self.getField('tags').set(self, value, **kwargs) |
---|
| 271 | |
---|
| 272 | tags = self.listTags() |
---|
| 273 | newEntries = [v for v in value if not v in tags] |
---|
| 274 | if not newEntries: |
---|
| 275 | return |
---|
| 276 | newTagsList = list(tags)+ list(newEntries) |
---|
| 277 | parent = self.aq_parent |
---|
| 278 | portal = self.portal_url.getPortalObject() |
---|
| 279 | while parent != portal: |
---|
| 280 | if parent.portal_type == 'Blog': |
---|
| 281 | break |
---|
| 282 | parent = parent.aq_parent |
---|
| 283 | parent.setTags(newTagsList, **kwargs) |
---|
| 284 | |
---|
| 285 | def listTags(self): |
---|
| 286 | """ Get the list of Tags from parent Blog """ |
---|
| 287 | tags = [] |
---|
| 288 | parent = self.aq_parent |
---|
| 289 | portal = self.portal_url.getPortalObject() |
---|
| 290 | while parent != portal: |
---|
| 291 | if parent.portal_type == 'Blog': |
---|
| 292 | tags = parent.getTags() |
---|
| 293 | break |
---|
| 294 | parent = parent.aq_parent |
---|
| 295 | return tuple(tags) |
---|
| 296 | |
---|
| 297 | def listAdesnceTemplates(self): |
---|
| 298 | """ return list of available adsence blocks """ |
---|
| 299 | pp = getToolByName(self, 'portal_properties') |
---|
| 300 | templates = () |
---|
| 301 | try: |
---|
| 302 | templates = pp.simpleblog_properties.getProperty('adsence_templates',()) |
---|
| 303 | except: |
---|
| 304 | pass |
---|
| 305 | return templates |
---|
| 306 | |
---|
| 307 | registerType(BlogEntry) |
---|