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 | |
---|
19 | schema = BaseFolderSchema + Schema(( |
---|
20 | StringField('id', |
---|
21 | required = 0, ## Still actually required, but |
---|
22 | ## the widget will supply the missing value |
---|
23 | ## on non-submits |
---|
24 | mode = "rw", |
---|
25 | accessor = "getId", |
---|
26 | mutator = "setId", |
---|
27 | default = None, |
---|
28 | widget = IdWidget(label = "Short Name", |
---|
29 | label_msgid = "label_short_name", |
---|
30 | description = "Should not contain spaces, underscores or mixed case. "\ |
---|
31 | "Short Name is part of the item's web address.", |
---|
32 | description_msgid = "help_shortname", |
---|
33 | visible = {'view' : 'visible', 'edit':'visible'}, |
---|
34 | i18n_domain = "plone"), |
---|
35 | ), |
---|
36 | StringField('title', |
---|
37 | required = 1, |
---|
38 | searchable = 1, |
---|
39 | default = '', |
---|
40 | accessor = 'Title', |
---|
41 | widget = StringWidget(label_msgid = "label_title", |
---|
42 | description_msgid = "help_title", |
---|
43 | i18n_domain = "plone"), |
---|
44 | ), |
---|
45 | StringField('description', |
---|
46 | searchable = 1, |
---|
47 | isMetadata = 1, |
---|
48 | accessor = 'Description', |
---|
49 | widget = TextAreaWidget(label = 'Description', |
---|
50 | label_msgid = "label_entry_description", |
---|
51 | description_msgid = "help_entry_description", |
---|
52 | i18n_domain = "SimpleBlog", |
---|
53 | raws = 3, |
---|
54 | description = 'Give a description for this entry.'),), |
---|
55 | TextField('body', |
---|
56 | searchable = 1, |
---|
57 | required = 0, |
---|
58 | primary = 1, |
---|
59 | default_content_type = 'text/html', |
---|
60 | default_output_type = 'text/html', |
---|
61 | allowable_content_types = ('text/plain','text/structured', 'text/html', 'text/restructured'), |
---|
62 | widget = RichWidget(label = 'Body', |
---|
63 | label_msgid = "label_entry_body", |
---|
64 | description_msgid = "help_entry_body", |
---|
65 | i18n_domain = "SimpleBlog", |
---|
66 | description = "Body of the blog")), |
---|
67 | |
---|
68 | LinesField('categories', |
---|
69 | accessor = 'EntryCategory', |
---|
70 | edit_accessor = 'EntryCategory', |
---|
71 | index = 'KeywordIndex', |
---|
72 | vocabulary = 'listCategories', |
---|
73 | widget = MultiSelectionWidget(format = 'select', |
---|
74 | label_msgid = "label_entry_categories", |
---|
75 | description_msgid = "help_entry_categories", |
---|
76 | i18n_domain = "SimpleBlog", |
---|
77 | label = 'Categories', |
---|
78 | description = 'Select to which categories this Entry belongs to')), |
---|
79 | LinesField('tags', |
---|
80 | accessor = 'EntryTag', |
---|
81 | mutator = 'setEntryTag', |
---|
82 | index = 'KeywordIndex', |
---|
83 | enforseVocabulary = 1, |
---|
84 | vocabulary = 'listTags', |
---|
85 | widget = KeywordWidget(label_msgid = "label_entry_tags", |
---|
86 | description_msgid = "help_entry_tags", |
---|
87 | i18n_domain = "SimpleBlog", |
---|
88 | label = 'Tags', |
---|
89 | description = 'Select tags for technorati.com')), |
---|
90 | |
---|
91 | BooleanField('alwaysOnTop', |
---|
92 | default = 0, |
---|
93 | index = 'FieldIndex:schema', |
---|
94 | widget = BooleanWidget(label = 'Entry is always listed on top.', |
---|
95 | label_msgid = "label_always_top", |
---|
96 | description_msgid = "help_always_top", |
---|
97 | i18n_domain = "SimpleBlog", |
---|
98 | description = 'Controls if the Entry (when published) shown as the first Entry. If not checked, the effective date is used.')), |
---|
99 | |
---|
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 | |
---|
110 | )) |
---|
111 | |
---|
112 | |
---|
113 | class BlogEntry(BaseFolder): |
---|
114 | """ |
---|
115 | A BlogEntry can exist inside a SimpleBlog Folder or an EntryFolder |
---|
116 | """ |
---|
117 | |
---|
118 | schema = schema |
---|
119 | |
---|
120 | global_allow = 0 |
---|
121 | |
---|
122 | content_icon = 'entry_icon.gif' |
---|
123 | |
---|
124 | filter_content_types = 1 |
---|
125 | allowed_content_types = ('TrackBack','Link', 'Image', 'File') |
---|
126 | |
---|
127 | actions = ({ |
---|
128 | 'id': 'view', |
---|
129 | 'name': 'View', |
---|
130 | 'action': 'string:${object_url}/blogentry_view', |
---|
131 | 'permissions': (CMFCorePermissions.View,) |
---|
132 | }, |
---|
133 | {'id': 'references', |
---|
134 | 'name': 'References', |
---|
135 | 'action': 'string:${object_url}/reference_edit', |
---|
136 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
137 | 'visible':0}, |
---|
138 | {'id': 'metadata', |
---|
139 | 'name': 'Properties', |
---|
140 | 'action': 'string:${object_url}/base_metadata', |
---|
141 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
142 | 'visible':0}) |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | def getAlwaysOnTop(self): |
---|
148 | if hasattr(self, 'alwaysOnTop'): |
---|
149 | if self.alwaysOnTop == None or self.alwaysOnTop == 0: |
---|
150 | return 0 |
---|
151 | else: |
---|
152 | return 1 |
---|
153 | else: |
---|
154 | return 0 |
---|
155 | |
---|
156 | def getIcon(self, relative_to_portal = 0): |
---|
157 | try: |
---|
158 | if self.getAlwaysOnTop() == 0: |
---|
159 | return 'entry_icon.gif' |
---|
160 | else: |
---|
161 | return 'entry_pin.gif' |
---|
162 | except: |
---|
163 | return 'entry_icon.gif' |
---|
164 | |
---|
165 | def listCategories(self): |
---|
166 | # traverse upwards in the tree to collect all the available categories |
---|
167 | # stop collecting when a SimpleBlog object is reached |
---|
168 | |
---|
169 | cats = [] |
---|
170 | parent = self.aq_parent |
---|
171 | portal = self.portal_url.getPortalObject() |
---|
172 | |
---|
173 | while parent != portal: |
---|
174 | if parent.portal_type == 'Blog' or parent.portal_type == 'BlogFolder': |
---|
175 | # add cats |
---|
176 | pcats = parent.getCategories() |
---|
177 | for c in pcats: |
---|
178 | if c not in cats: |
---|
179 | cats.append(c) |
---|
180 | if parent.portal_type == 'Blog': |
---|
181 | break |
---|
182 | parent = parent.aq_parent |
---|
183 | |
---|
184 | # add the global categories |
---|
185 | for c in self.simpleblog_tool.getGlobalCategories(): |
---|
186 | if not c in cats: |
---|
187 | cats.append(c) |
---|
188 | cats.sort() |
---|
189 | return tuple(cats) |
---|
190 | |
---|
191 | def start(self): |
---|
192 | return self.getEffectiveDate() |
---|
193 | |
---|
194 | def end(self): |
---|
195 | """ |
---|
196 | return the same data as start() since an entry is not an event but an item that is published on a specific |
---|
197 | date. We want the entries in the calendar to appear on only one day. |
---|
198 | """ |
---|
199 | return self.getEffectiveDate() |
---|
200 | |
---|
201 | #function for sending ping |
---|
202 | def sendTrackBack(self): |
---|
203 | message = "TrackBack sent" |
---|
204 | title = self.title |
---|
205 | src_url = self.absolute_url() |
---|
206 | blog = self.simpleblog_tool.getFrontPage(self) |
---|
207 | blog_name = blog.Title() |
---|
208 | excerpt=self.description |
---|
209 | agent = "SimpleBlog" |
---|
210 | result=[] |
---|
211 | for i in self.getSendTrackBackURLs(): |
---|
212 | ping_url=i |
---|
213 | err,mes = post_trackback(self, |
---|
214 | ping_url=ping_url, |
---|
215 | title = title, |
---|
216 | src_url = src_url, |
---|
217 | blog_name = blog_name, |
---|
218 | excerpt=self.description, |
---|
219 | agent = "SimpleBlog", |
---|
220 | charset = "utf-8") |
---|
221 | result.append((err,mes)) |
---|
222 | result.append(("excerpt",self.description)) |
---|
223 | return result |
---|
224 | |
---|
225 | def getTrackbacks(self): |
---|
226 | """ """ |
---|
227 | return self.listFolderContents(spec="TrackBack") |
---|
228 | |
---|
229 | def setEntryTag(self, value, **kwargs): |
---|
230 | """ Update tags in the Entry in parent Blog """ |
---|
231 | value = list(value) |
---|
232 | value.sort() |
---|
233 | self.getField('tags').set(self, value, **kwargs) |
---|
234 | |
---|
235 | tags = self.listTags() |
---|
236 | newEntries = [v for v in value if not v in tags] |
---|
237 | if not newEntries: |
---|
238 | return |
---|
239 | newTagsList = list(tags)+ list(newEntries) |
---|
240 | parent = self.aq_parent |
---|
241 | portal = self.portal_url.getPortalObject() |
---|
242 | while parent != portal: |
---|
243 | if parent.portal_type == 'Blog': |
---|
244 | break |
---|
245 | parent = parent.aq_parent |
---|
246 | parent.setTags(newTagsList, **kwargs) |
---|
247 | |
---|
248 | def listTags(self): |
---|
249 | """ Get the list of Tags from parent Blog """ |
---|
250 | tags = [] |
---|
251 | parent = self.aq_parent |
---|
252 | portal = self.portal_url.getPortalObject() |
---|
253 | |
---|
254 | while parent != portal: |
---|
255 | if parent.portal_type == 'Blog': |
---|
256 | tags = parent.getTags() |
---|
257 | break |
---|
258 | parent = parent.aq_parent |
---|
259 | return tuple(tags) |
---|
260 | |
---|
261 | registerType(BlogEntry) |
---|