[1] | 1 | from Products.Archetypes.public import BaseSchema, BaseFolderSchema, Schema |
---|
| 2 | from Products.Archetypes.public import StringField, TextField, LinesField, BooleanField, ReferenceField |
---|
| 3 | from Products.Archetypes.public import TextAreaWidget, VisualWidget, MultiSelectionWidget, StringWidget, IdWidget, LinesWidget, KeywordWidget, SelectionWidget |
---|
| 4 | from Products.Archetypes.public import RichWidget, BooleanWidget |
---|
| 5 | from Products.Archetypes.public import BaseContent, registerType, BaseFolder |
---|
| 6 | from Products.CMFCore import CMFCorePermissions |
---|
| 7 | |
---|
| 8 | from Products.CMFCore.permissions import View |
---|
| 9 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
| 10 | from Products.CMFCore.permissions import ManageProperties |
---|
| 11 | |
---|
| 12 | from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import * |
---|
| 13 | from DateTime import DateTime |
---|
| 14 | from Products.SimpleBlog.Permissions import CROSS_POST_PERMISSION |
---|
| 15 | from Products.SimpleBlog.config import ENTRY_IS_FOLDERISH |
---|
| 16 | from Products.SimpleBlog.util import post_trackback |
---|
| 17 | from Products.ATContentTypes.content.document import finalizeATCTSchema |
---|
| 18 | from Products.ATContentTypes.content.base import ATCTContent, ATCTFolder |
---|
| 19 | |
---|
| 20 | from Products.CMFCore.utils import getToolByName |
---|
| 21 | import string,os,urllib,httplib,urlparse,re |
---|
| 22 | import sys |
---|
| 23 | from Products.SimpleBlog.util import * |
---|
| 24 | from Products.SimpleBlog.config import DIGG_TOPICS |
---|
| 25 | |
---|
| 26 | if ENTRY_IS_FOLDERISH: |
---|
| 27 | schema = ATCTFolder.schema.copy() |
---|
| 28 | parentClass = ATCTFolder |
---|
| 29 | else: |
---|
| 30 | schema = ATCTContent.schema.copy() |
---|
| 31 | parentClass = ATCTContent |
---|
| 32 | |
---|
| 33 | schema = schema + Schema(( |
---|
| 34 | StringField('description', |
---|
| 35 | searchable=1, |
---|
| 36 | isMetadata=1, |
---|
| 37 | accessor='Description', |
---|
| 38 | widget=TextAreaWidget(label='Description', |
---|
| 39 | label_msgid="label_entry_description", |
---|
| 40 | description_msgid="help_entry_description", |
---|
| 41 | i18n_domain="SimpleBlog", |
---|
| 42 | description='Give a description for this entry.')), |
---|
| 43 | TextField('body', |
---|
| 44 | searchable=1, |
---|
| 45 | required=0, |
---|
| 46 | primary=1, |
---|
| 47 | default_content_type='text/html', |
---|
| 48 | default_output_type='text/html', |
---|
| 49 | allowable_content_types=('text/plain','text/structured', 'text/html', 'text/restructured'), |
---|
| 50 | widget=RichWidget(label='Body', |
---|
| 51 | label_msgid="label_entry_body", |
---|
| 52 | description_msgid="help_entry_body", |
---|
| 53 | i18n_domain="SimpleBlog", |
---|
| 54 | description="")), |
---|
| 55 | |
---|
| 56 | ReferenceField('crossPosts', |
---|
| 57 | multiValued=1, |
---|
| 58 | required=0, |
---|
| 59 | relationship='AppearsIn', |
---|
| 60 | write_permission=CROSS_POST_PERMISSION, |
---|
| 61 | allowed_types=('Blog',), |
---|
| 62 | widget=ReferenceBrowserWidget(condition="python:0", # this line have to be removed in order to be visible/editable |
---|
| 63 | force_close_on_insert=1, |
---|
| 64 | i18n_domain="SimpleBlog", |
---|
| 65 | label_msgid="label_crosspost", |
---|
| 66 | description_msgid="help_crosspost", |
---|
| 67 | label='Cross posts', |
---|
| 68 | description='Select one or more other blogs where this entry will appear in when published additionally to this blog.')), |
---|
| 69 | BooleanField('alwaysOnTop', |
---|
| 70 | default=0, |
---|
| 71 | index='FieldIndex:schema', |
---|
| 72 | widget=BooleanWidget(label='Entry is always listed on top', |
---|
| 73 | label_msgid="label_always_top", |
---|
| 74 | description_msgid="help_always_top", |
---|
| 75 | i18n_domain="SimpleBlog", |
---|
| 76 | description='Controls if the Entry (when published) shown as the first Entry. If not checked, the effective date is used.')), |
---|
| 77 | LinesField('categories', |
---|
| 78 | accessor='EntryCategory', |
---|
| 79 | edit_accessor='EntryCategory', |
---|
| 80 | index='KeywordIndex', |
---|
| 81 | vocabulary='listCategories', |
---|
| 82 | widget=MultiSelectionWidget(format='select', |
---|
| 83 | label_msgid="label_entry_categories", |
---|
| 84 | description_msgid="help_entry_categories", |
---|
| 85 | i18n_domain="SimpleBlog", |
---|
| 86 | label='Categories', |
---|
| 87 | description='Select to which categories this Entry belongs to')), |
---|
| 88 | LinesField('tags', |
---|
| 89 | accessor = 'EntryTag', |
---|
| 90 | mutator = 'setEntryTag', |
---|
| 91 | index = 'KeywordIndex', |
---|
| 92 | enforseVocabulary = 1, |
---|
| 93 | vocabulary = 'listTags', |
---|
| 94 | widget = KeywordWidget(label_msgid = "label_entry_tags", |
---|
| 95 | description_msgid = "help_entry_tags", |
---|
| 96 | i18n_domain = "SimpleBlog", |
---|
| 97 | label = 'Tags', |
---|
| 98 | description = 'Select tags for technorati.com')), |
---|
| 99 | |
---|
| 100 | BooleanField('alwaysOnTop', |
---|
| 101 | default = 0, |
---|
| 102 | index = 'FieldIndex:schema', |
---|
| 103 | widget = BooleanWidget(label = 'Entry is always listed on top.', |
---|
| 104 | label_msgid = "label_always_top", |
---|
| 105 | description_msgid = "help_always_top", |
---|
| 106 | i18n_domain = "SimpleBlog", |
---|
| 107 | description = 'Controls if the Entry (when published) shown as the first Entry. If not checked, the effective date is used.')), |
---|
| 108 | LinesField('sendTrackBackURLs', |
---|
| 109 | languageIndependent = True, |
---|
| 110 | searchable = True, |
---|
| 111 | widget = LinesWidget(label = "sendTrackBackURLs", |
---|
| 112 | label_msgid = "label_sendTrackBackURLs", |
---|
| 113 | description = ("URL for sending trackbacks"), |
---|
| 114 | description_msgid = "help_event_attendees", |
---|
| 115 | i18n_domain = "plone")), |
---|
| 116 | StringField('diggTopic', |
---|
| 117 | default='offbeat_news', |
---|
| 118 | vocabulary=DIGG_TOPICS, |
---|
| 119 | widget=SelectionWidget(label='Digg topic', |
---|
| 120 | label_msgid="label_digg_topic", |
---|
| 121 | description_msgid="help_digg_topic", |
---|
| 122 | i18n_domain="SimpleBlog", |
---|
| 123 | description='Choose the digg topic.')), |
---|
| 124 | )) |
---|
| 125 | |
---|
| 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. |
---|
| 129 | finalizeATCTSchema(schema) |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | class BlogEntry(parentClass): |
---|
| 133 | """ |
---|
| 134 | A BlogEntry can exist inside a SimpleBlog Folder or an EntryFolder |
---|
| 135 | """ |
---|
| 136 | # Standard content type setup |
---|
| 137 | portal_type = meta_type = 'BlogEntry' |
---|
| 138 | archetype_name = 'Blog Entry' |
---|
| 139 | content_icon='entry_icon.gif' |
---|
| 140 | schema = schema |
---|
| 141 | global_allow=0 |
---|
| 142 | allow_discussion = 1 |
---|
| 143 | |
---|
| 144 | default_view = 'blogentry_view' |
---|
| 145 | immediate_view = 'blogentry_view' |
---|
| 146 | |
---|
| 147 | # Make sure we get title-to-id generation when an object is created |
---|
| 148 | _at_rename_after_creation = True |
---|
| 149 | |
---|
| 150 | if ENTRY_IS_FOLDERISH: |
---|
| 151 | filter_content_types=1 |
---|
| 152 | allowed_content_types=('TrackBack') #('Link', 'Image', 'File', 'TrackBack') |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | def canSetDefaultPage(self): |
---|
| 156 | return False |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | def getAlwaysOnTop(self): |
---|
| 160 | if hasattr(self, 'alwaysOnTop'): |
---|
| 161 | if self.alwaysOnTop==None or self.alwaysOnTop==0: |
---|
| 162 | return 0 |
---|
| 163 | else: |
---|
| 164 | return 1 |
---|
| 165 | else: |
---|
| 166 | return 0 |
---|
| 167 | |
---|
| 168 | def getIcon(self, relative_to_portal=0): |
---|
| 169 | try: |
---|
| 170 | if self.getAlwaysOnTop()==0: |
---|
| 171 | return 'entry_icon.gif' |
---|
| 172 | else: |
---|
| 173 | return 'entry_pin.gif' |
---|
| 174 | except: |
---|
| 175 | return 'entry_icon.gif' |
---|
| 176 | |
---|
| 177 | 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 | |
---|
| 181 | cats=[] |
---|
| 182 | parent=self.aq_parent |
---|
| 183 | portal=self.portal_url.getPortalObject() |
---|
| 184 | |
---|
| 185 | while parent!=portal: |
---|
| 186 | if parent.portal_type=='Blog' or parent.portal_type=='BlogFolder': |
---|
| 187 | # add cats |
---|
| 188 | pcats=parent.getCategories() |
---|
| 189 | for c in pcats: |
---|
| 190 | if c not in cats: |
---|
| 191 | cats.append(c) |
---|
| 192 | if parent.portal_type=='Blog': |
---|
| 193 | break |
---|
| 194 | parent=parent.aq_parent |
---|
| 195 | |
---|
| 196 | # add the global categories |
---|
| 197 | for c in self.simpleblog_tool.getGlobalCategories(): |
---|
| 198 | if not c in cats: |
---|
| 199 | cats.append(c) |
---|
| 200 | cats.sort() |
---|
| 201 | return tuple(cats) |
---|
| 202 | |
---|
| 203 | def start(self): |
---|
| 204 | return self.getEffectiveDate() |
---|
| 205 | |
---|
| 206 | 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. |
---|
| 210 | """ |
---|
| 211 | return self.getEffectiveDate() |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | # ============================= |
---|
| 217 | |
---|
| 218 | #function for sending ping |
---|
| 219 | def sendTrackBack(self): |
---|
| 220 | message = "TrackBack sent" |
---|
| 221 | title = self.title |
---|
| 222 | src_url = self.absolute_url() |
---|
| 223 | blog = self.simpleblog_tool.getFrontPage(self) |
---|
| 224 | blog_name = blog.Title() |
---|
| 225 | excerpt=self.description |
---|
| 226 | agent = "SimpleBlog" |
---|
| 227 | result=[] |
---|
| 228 | for i in self.getSendTrackBackURLs(): |
---|
| 229 | ping_url=i |
---|
| 230 | err,mes = post_trackback(self, |
---|
| 231 | ping_url=ping_url, |
---|
| 232 | title = title, |
---|
| 233 | src_url = src_url, |
---|
| 234 | blog_name = blog_name, |
---|
| 235 | excerpt=self.description, |
---|
| 236 | agent = "SimpleBlog", |
---|
| 237 | charset = "utf-8") |
---|
| 238 | result.append((err,mes)) |
---|
| 239 | result.append(("excerpt",self.description)) |
---|
| 240 | return result |
---|
| 241 | |
---|
| 242 | def getTrackbacks(self): |
---|
| 243 | """ """ |
---|
| 244 | return self.listFolderContents(spec="TrackBack") |
---|
| 245 | |
---|
| 246 | def setEntryTag(self, value, **kwargs): |
---|
| 247 | """ Update tags in the Entry in parent Blog """ |
---|
| 248 | value = list(value) |
---|
| 249 | value.sort() |
---|
| 250 | self.getField('tags').set(self, value, **kwargs) |
---|
| 251 | |
---|
| 252 | tags = self.listTags() |
---|
| 253 | newEntries = [v for v in value if not v in tags] |
---|
| 254 | if not newEntries: |
---|
| 255 | return |
---|
| 256 | newTagsList = list(tags)+ list(newEntries) |
---|
| 257 | parent = self.aq_parent |
---|
| 258 | portal = self.portal_url.getPortalObject() |
---|
| 259 | while parent != portal: |
---|
| 260 | if parent.portal_type == 'Blog': |
---|
| 261 | break |
---|
| 262 | parent = parent.aq_parent |
---|
| 263 | parent.setTags(newTagsList, **kwargs) |
---|
| 264 | |
---|
| 265 | def listTags(self): |
---|
| 266 | """ Get the list of Tags from parent Blog """ |
---|
| 267 | tags = [] |
---|
| 268 | parent = self.aq_parent |
---|
| 269 | portal = self.portal_url.getPortalObject() |
---|
| 270 | while parent != portal: |
---|
| 271 | if parent.portal_type == 'Blog': |
---|
| 272 | tags = parent.getTags() |
---|
| 273 | break |
---|
| 274 | parent = parent.aq_parent |
---|
| 275 | return tuple(tags) |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | registerType(BlogEntry) |
---|