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

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

Building directory structure

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