source: products/SimpleBlog/branches/plone-2.1-Blogging-APIs/Blog.py @ 3665

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

Building directory structure

File size: 10.8 KB
Line 
1from Products.Archetypes.public import *
2from Products.Archetypes.utils import  unique
3from Products.CMFCore import CMFCorePermissions
4from DateTime import DateTime
5from config import DISPLAY_MODE
6import Permissions
7from Products.CMFCore.utils import getToolByName
8
9import MetaWeblogAPI
10import BloggerAPI
11import MovableTypeAPI
12
13
14schema = BaseFolderSchema +  Schema((
15    StringField('id',
16                required=0, ## Still actually required, but
17                            ## the widget will supply the missing value
18                            ## on non-submits
19                mode="rw",
20                accessor="getId",
21                mutator="setId",
22                default=None,
23                widget=IdWidget(label="Short Name",
24                                label_msgid="label_short_name",
25                                description="Should not contain spaces, underscores or mixed case. "\
26                                            "Short Name is part of the item's web address.",
27                                description_msgid="help_shortname",
28                                visible={'view' : 'visible'},
29                                i18n_domain="plone"),
30                ),
31    StringField('title',
32                required=1,
33                searchable=1,
34                default='',
35                accessor='Title',
36                widget=StringWidget(label_msgid="label_title",
37                                    description_msgid="help_title",
38                                    i18n_domain="plone"),
39                ),
40    StringField('description',
41                isMetadata=1,
42                accessor='Description',
43                searchable=1,               
44                widget=TextAreaWidget(label='Description', 
45                                      label_msgid="label_blog_description",
46                                      description_msgid="help_blog_description",
47                                      i18n_domain="SimpleBlog",
48                                      description='Give a description for this SimpleBlog.'),),
49    StringField('displayMode',
50                vocabulary=DISPLAY_MODE,
51                widget=SelectionWidget(label='Display Mode', 
52                                       label_msgid="label_display_mode",
53                                       description_msgid="help_display_mode",
54                                       i18n_domain="SimpleBlog",
55                                       description='Choose the display mode.'),
56                default='descriptionOnly'),
57    IntegerField('displayItems', 
58                widget=IntegerWidget(label='BlogEntries to display', 
59                                      label_msgid="label_display_items",
60                                      description_msgid="help_display_items",
61                                      i18n_domain="SimpleBlog",
62                                      description='Set the maximum number of BlogEntries to display.'), 
63                 default=20),
64    LinesField('categories',
65               widget=LinesWidget(label='Possible Categories', 
66                                  label_msgid="label_categories",
67                                  description_msgid="help_categories",
68                                  i18n_domain="SimpleBlog",
69                                  description='Supply the list of possible categories that can be used in SimpleBlog Entries.'),
70               ),
71    LinesField('tags',
72               mutator = 'setTags',
73               widget=LinesWidget(label="Tags",
74                                  description='List of tags.'),
75               ),
76    BooleanField('tagsEnabled',
77                  accessor = 'isTagsEnabled',
78                  default = 1,
79                  schemata = 'interface',
80                  widget = BooleanWidget(label='Enable technorati tags',
81                                     label_msgid="label_enable_tags",
82                                     description_msgid="help_enable_tags",),
83              ),
84    BooleanField('allowTrackback',
85                  default = 1,
86                  schemata = 'interface', 
87                  widget=BooleanWidget(label="Allow Trackback", 
88                                       label_msgid="label_allow_trackback",
89                                       description_msgid="help_allow_trackback",),
90               ),
91    # used to be new trackbaks notification email address
92    StringField('adminEmail',
93                accessor = 'getAdminEmail',
94                mutator = 'setAdminEmail',
95                schemata = 'interface',
96                default = '',
97                widget=StringWidget(label="Administrator's email", 
98                                    label_msgid="label_adminEmail",
99                                    description_msgid="help_adminEmail",
100                                    i18n_domain="SimpleBlog",
101                                                    condition="python:0", # this line have to be removed in order to be visible/editable
102                                    description="Enter administrator's email for receaving notification about blog's activity"),
103               ),
104    BooleanField('allowDelicious',
105                default = 1,
106                accessor = 'isDeliciousEnabled',
107                schemata = 'interface', 
108                widget=BooleanWidget(label="Turn Delicious bookmarklet",
109                                    label_msgid="label_allow_delicious",
110                                    description_msgid="help_allow_delicious"),
111                ),
112    BooleanField('allowDigg',
113                default = 1,
114                accessor = 'isDiggEnabled',
115                schemata = 'interface',
116                widget=BooleanWidget(label="Turn Digg bookmarklet",
117                                    label_msgid="label_allow_digg",
118                                    description_msgid="help_allow_digg"),
119                ),
120    BooleanField('allowYahoo',
121                default = 1,
122                accessor = 'isYahooEnabled',
123                schemata = 'interface', 
124                widget=BooleanWidget(label="Turn Yahoo bookmarklet",
125                                    label_msgid="label_allow_yahoo",
126                                    description_msgid="help_allow_yahoo"),
127                ),
128    BooleanField('allowGoogle',
129                default = 1,
130                accessor = 'isGoogleEnabled',
131                schemata = 'interface',
132                widget=BooleanWidget(label="Turn Google bookmarklet",
133                                    label_msgid="label_allow_google",
134                                    description_msgid="help_allow_google"),
135                ),
136    BooleanField('allowSpurl',
137                default = 1,
138                accessor = 'isSpurlEnabled',
139                schemata = 'interface', 
140                widget=BooleanWidget(label="Turn Spurl bookmarklet",
141                                    label_msgid="label_allow_spurl",
142                                    description_msgid="help_allow_spurl"),
143                ),
144    #BooleanField('allowComments',
145    #              default = 1,
146    #              schemata = 'interface',
147    #              widget=BooleanWidget(label="Allow Comments",
148    #                                   label_msgid="label_allow_comments",
149    #                                   description_msgid="help_allow_comments",),
150    #           ),
151    #BooleanField('expandMainPageComments',
152    #              default = 0,
153    #              schemata = 'interface',
154    #              widget = BooleanWidget(label='Expand comments on main page',
155    #                                 label_msgid="label_expand_mainpage_comments",
156    #                                 description_msgid="help_expand_mainpage_comments",),
157    #          ),
158
159        ))
160
161
162class Blog(BaseFolder):
163    """
164Blog
165    """
166    allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet')
167    filter_content_types=1   
168    global_allow=1
169    schema=schema
170
171    blogger = None
172    metaWeblog = None
173   
174    content_icon='simpleblog_icon.gif'
175
176    actions = ({'id': 'view',
177                'name': 'View',
178                'action': 'string:${object_url}/simpleblog_view',
179                'permissions': (CMFCorePermissions.View,) },
180        {'id': 'references',
181          'name': 'References',
182          'action': 'string:${object_url}/reference_edit',
183          'permissions': (CMFCorePermissions.ModifyPortalContent,),
184          'visible':0},
185        {'id': 'metadata',
186          'name': 'Properties',
187          'action': 'string:${object_url}/base_metadata',
188          'permissions': (CMFCorePermissions.ModifyPortalContent,),
189          'visible':0})
190
191    def initializeArchetype(self, **kwargs):
192        BaseFolder.initializeArchetype(self, **kwargs)
193        RPCAuth = self.simpleblog_tool.findRPCAuth(self)
194
195        # Setup the MetaWeblog API
196        self.metaWeblog = MetaWeblogAPI.MetaWeblogAPI().__of__(self)
197        self.metaWeblog.setupRPCAuth(RPCAuth)
198       
199        # Setup the Blogger API
200        self.blogger = BloggerAPI.BloggerAPI().__of__(self)
201        self.blogger.setupRPCAuth(RPCAuth)
202
203        # Setup the MovableTypeAPI API
204        self.mt = MovableTypeAPI.MovableTypeAPI().__of__(self)
205        self.mt.setupRPCAuth(RPCAuth)   
206
207    def manage_afterAdd(self, item, container):
208        BaseFolder.manage_afterAdd(self, item, container)
209        if self.simpleblog_tool.getCreatePortletOnBlogCreation():
210            if not hasattr(item.aq_base, 'right_slots'):
211                item._setProperty('right_slots', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines')
212            if not hasattr(item.aq_base, 'column_two_portlets'):
213                item._setProperty('column_two_portlets', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines')
214
215    def synContentValues(self):
216        # get brains for items that are published within the context of this blog.
217        entries = self.simpleblog_tool.searchForEntries(self, maxResults=0)
218
219        # convert to objects
220        objs = [e.getObject() for e in entries]
221        return objs
222
223    def setTags(self, value, **kwargs):
224        """ Save tags in lower case """
225        value = unique(value)
226        value.sort(lambda x, y: cmp(x,y))
227        self.getField('tags').set(self, value, **kwargs)
228
229    def getAdminEmail(self):
230        """ return blog admin email or root email """
231        val = self.getField('adminEmail').get(self)
232        if not val:
233            purl = getToolByName(self, 'portal_url')
234            val = purl.getPortalObject().getProperty("trackback_notification_email", "")
235        return val
236
237    def listCategories(self):
238        cats=self.getCategories()
239           
240        # add the global categories
241        for c in self.simpleblog_tool.getGlobalCategories():
242            if not c in cats:
243                cats.append(c)           
244        cats = list(cats)
245        cats.sort()
246        return tuple(cats)               
247
248registerType(Blog)
249
Note: See TracBrowser for help on using the repository browser.