source: products/SimpleBlog/branches/plone-2.0.5-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: 8.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    StringField('adminEmail',
92                accessor = 'getAdminEmail',
93                mutator = 'setAdminEmail',
94                schemata = 'interface',
95                default = '',
96                widget=StringWidget(label="Administrator's email", 
97                                    label_msgid="label_adminEmail",
98                                    description_msgid="help_adminEmail",
99                                    i18n_domain="SimpleBlog",
100                                    condition="python:0",
101                                    description="Enter administrator's email for receaving notification about blog's activity"),
102               )
103    #BooleanField('allowComments',
104    #              default = 1,
105    #              schemata = 'interface',
106    #              widget=BooleanWidget(label="Allow Comments",
107    #                                   label_msgid="label_allow_comments",
108    #                                   description_msgid="help_allow_comments",),
109    #           ),
110    #BooleanField('expandMainPageComments',
111    #              default = 0,
112    #              schemata = 'interface',
113    #              widget = BooleanWidget(label='Expand comments on main page',
114    #                                 label_msgid="label_expand_mainpage_comments",
115    #                                 description_msgid="help_expand_mainpage_comments",),
116    #          ),
117
118        ))
119
120
121class Blog(BaseFolder):
122    """
123Blog
124    """
125    allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet')
126    filter_content_types=1   
127    global_allow=1
128    schema=schema
129
130    blogger = None
131    metaWeblog = None
132   
133    content_icon='simpleblog_icon.gif'
134
135    actions = ({'id': 'view',
136                'name': 'View',
137                'action': 'string:${object_url}/simpleblog_view',
138                'permissions': (CMFCorePermissions.View,) },
139        {'id': 'references',
140          'name': 'References',
141          'action': 'string:${object_url}/reference_edit',
142          'permissions': (CMFCorePermissions.ModifyPortalContent,),
143          'visible':0},
144        {'id': 'metadata',
145          'name': 'Properties',
146          'action': 'string:${object_url}/base_metadata',
147          'permissions': (CMFCorePermissions.ModifyPortalContent,),
148          'visible':0})
149
150    def initializeArchetype(self, **kwargs):
151        BaseFolder.initializeArchetype(self, **kwargs)
152        RPCAuth = self.simpleblog_tool.findRPCAuth(self)
153
154        # Setup the MetaWeblog API
155        self.metaWeblog = MetaWeblogAPI.MetaWeblogAPI().__of__(self)
156        self.metaWeblog.setupRPCAuth(RPCAuth)
157       
158        # Setup the Blogger API
159        self.blogger = BloggerAPI.BloggerAPI().__of__(self)
160        self.blogger.setupRPCAuth(RPCAuth)
161
162        # Setup the MovableTypeAPI API
163        self.mt = MovableTypeAPI.MovableTypeAPI().__of__(self)
164        self.mt.setupRPCAuth(RPCAuth)   
165
166    def manage_afterAdd(self, item, container):
167        BaseFolder.manage_afterAdd(self, item, container)
168        if self.simpleblog_tool.getCreatePortletOnBlogCreation():
169            if not hasattr(item.aq_base, 'right_slots'):
170                item._setProperty('right_slots', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines')
171            if not hasattr(item.aq_base, 'column_two_portlets'):
172                item._setProperty('column_two_portlets', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines')
173
174    def synContentValues(self):
175        # get brains for items that are published within the context of this blog.
176        entries = self.simpleblog_tool.searchForEntries(self, maxResults=0)
177
178        # convert to objects
179        objs = [e.getObject() for e in entries]
180        return objs
181
182    def setTags(self, value, **kwargs):
183        """ Save tags in lower case """
184        value = unique(value)
185        value.sort(lambda x, y: cmp(x,y))
186        self.getField('tags').set(self, value, **kwargs)
187
188    def getAdminEmail(self):
189        """ return blog admin email or root email """
190        val = self.getField('adminEmail').get(self)
191        if not val:
192            purl = getToolByName(self, 'portal_url')
193            val = purl.getPortalObject().getProperty("trackback_notification_email", "")
194        return val
195
196    def listCategories(self):
197        cats=self.getCategories()
198           
199        # add the global categories
200        for c in self.simpleblog_tool.getGlobalCategories():
201            if not c in cats:
202                cats.append(c)           
203        cats = list(cats)
204        cats.sort()
205        return tuple(cats)               
206
207registerType(Blog)
208
Note: See TracBrowser for help on using the repository browser.