source: products/SimpleBlog/tags/1.5.0/BlogEntry.py @ 2743

Last change on this file since 2743 was 1, checked in by myroslav, 18 years ago

Building directory structure

File size: 11.9 KB
Line 
1from 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
8from Products.CMFCore import CMFCorePermissions
9
10from Products.CMFCore.utils import getToolByName
11
12from DateTime import DateTime
13
14import Permissions
15import string,os,urllib,httplib,urlparse,re
16import sys
17from util import *
18
19schema  =  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    LinesField('sendTrackBackURLs',
100               languageIndependent = True,
101               searchable = True,
102               widget = LinesWidget(label = "sendTrackBackURLs",
103                                  label_msgid = "label_sendTrackBackURLs",
104                                  description = ("URL for sending trackbacks"),
105                                  description_msgid = "help_event_attendees",                             
106                                  i18n_domain = "plone")),
107
108    BooleanField('enableTopAdsence',
109                 widget = BooleanWidget(format = 'select', 
110                           label_msgid = "label_enable_top_adsence",
111                           description_msgid = "help_enable_top_adsence",
112                           i18n_domain = "SimpleBlog",
113                           label = 'Enable top Adsence block',
114                           description = None)),
115    StringField('topAdsence',
116                vocabulary = 'listAdesnceTemplates',
117                widget = SelectionWidget(format = 'select', 
118                        label_msgid = "label_top_adsence",
119                        description_msgid = "help_top_adsence",
120                        i18n_domain = "SimpleBlog",
121                        label = 'Top Adsence',
122                        description = None)),
123    BooleanField('enableBottomAdsence',
124                 widget = BooleanWidget(format = 'select', 
125                           label_msgid = "label_enable_bottom_adsence",
126                           description_msgid = "help_enable_bottom_adsence",
127                           i18n_domain = "SimpleBlog",
128                           label = 'Enable bottom Adsence block',
129                           description = None)),
130    StringField('bottomAdsence',
131                vocabulary = 'listAdesnceTemplates',
132                widget = SelectionWidget(format = 'select', 
133                        label_msgid = "label_bottom_adsence",
134                        description_msgid = "help_bottom_adsence",
135                        i18n_domain = "SimpleBlog",
136                        label = 'Bottom Adsence',
137                        description = None)),
138    ))
139
140
141class BlogEntry(BaseFolder):
142    """
143    A BlogEntry can exist inside a SimpleBlog Folder or an EntryFolder
144    """
145
146    schema  =  schema
147
148    global_allow = 0
149   
150    content_icon = 'entry_icon.gif'
151   
152    filter_content_types = 1
153    allowed_content_types = ('TrackBack','Link', 'Image', 'File')
154   
155    actions  =  ({
156       'id': 'view',
157        'name': 'View',
158        'action': 'string:${object_url}/blogentry_view',
159        'permissions': (CMFCorePermissions.View,)
160        },
161        {'id': 'references',
162          'name': 'References',
163          'action': 'string:${object_url}/reference_edit',
164          'permissions': (CMFCorePermissions.ModifyPortalContent,),
165          'visible':0},
166        {'id': 'metadata',
167          'name': 'Properties',
168          'action': 'string:${object_url}/base_metadata',
169          'permissions': (CMFCorePermissions.ModifyPortalContent,),
170          'visible':0})
171
172
173   
174
175    def getAlwaysOnTop(self):
176        if hasattr(self, 'alwaysOnTop'):
177            if self.alwaysOnTop == None or self.alwaysOnTop == 0:
178                return 0
179            else:
180                return 1
181        else:
182            return 0
183           
184    def getIcon(self, relative_to_portal = 0):
185        try:
186            if self.getAlwaysOnTop() == 0:
187                return 'entry_icon.gif'
188            else:
189                return 'entry_pin.gif'
190        except:
191            return 'entry_icon.gif'
192       
193    def listCategories(self):
194        # traverse upwards in the tree to collect all the available categories
195        # stop collecting when a SimpleBlog object is reached
196       
197        cats = []
198        parent = self.aq_parent
199        portal = self.portal_url.getPortalObject()
200       
201        while parent != portal:
202           if parent.portal_type == 'Blog' or parent.portal_type == 'BlogFolder':
203               # add cats
204               pcats = parent.getCategories()
205               for c in pcats:
206                   if c not in cats:
207                       cats.append(c)
208               if parent.portal_type == 'Blog':
209                   break
210           parent = parent.aq_parent
211           
212        # add the global categories
213        for c in self.simpleblog_tool.getGlobalCategories():
214            if not c in cats:
215                cats.append(c)           
216        cats.sort()
217        return tuple(cats)
218
219    def start(self):
220        return self.getEffectiveDate()
221       
222    def end(self):
223        """
224        return the same data as start() since an entry is not an event but an item that is published on a specific
225        date. We want the entries in the calendar to appear on only one day.
226        """
227        return self.getEffectiveDate()
228
229    #function for sending ping
230    def sendTrackBack(self):
231        message = "TrackBack sent"
232        title = self.title
233        src_url = self.absolute_url()
234        blog = self.simpleblog_tool.getFrontPage(self)
235        blog_name = blog.Title()
236        excerpt=self.description
237        agent = "SimpleBlog"
238        result=[]
239        for i in self.getSendTrackBackURLs():
240            ping_url=i
241            err,mes = post_trackback(self,
242                                     ping_url=ping_url, 
243                                     title = title,
244                                     src_url = src_url,
245                                     blog_name = blog_name,
246                                     excerpt=self.description,
247                                     agent = "SimpleBlog",
248                                     charset = "utf-8")
249            result.append((err,mes))
250        result.append(("excerpt",self.description))
251        return result
252
253    def getTrackbacks(self):
254        """ """
255        return self.listFolderContents(spec="TrackBack")
256
257    def setEntryTag(self, value, **kwargs):
258        """ Update tags in the Entry in parent Blog """
259        value = list(value)
260        value.sort()
261        self.getField('tags').set(self, value, **kwargs)
262
263        tags = self.listTags()
264        newEntries = [v for v in value if not v in tags]
265        if not newEntries:
266            return
267        newTagsList = list(tags)+ list(newEntries)
268        parent = self.aq_parent
269        portal = self.portal_url.getPortalObject()
270        while parent != portal:
271           if parent.portal_type == 'Blog':
272               break
273           parent = parent.aq_parent
274        parent.setTags(newTagsList, **kwargs)
275
276    def listTags(self):
277        """ Get the list of Tags from parent Blog """
278        tags = []
279        parent = self.aq_parent
280        portal = self.portal_url.getPortalObject()
281        while parent != portal:
282           if parent.portal_type == 'Blog':
283               tags = parent.getTags()
284               break
285           parent = parent.aq_parent
286        return tuple(tags)
287
288    def listAdesnceTemplates(self):
289        """ return list of available adsence blocks """
290        pp = getToolByName(self, 'portal_properties')
291        templates = ()
292        try:
293            templates = pp.simpleblog_properties.getProperty('adsence_templates',())
294        except:
295            pass
296        return templates
297
298registerType(BlogEntry)
Note: See TracBrowser for help on using the repository browser.