source: products/SimpleBlog/tags/1.3.5qg/Blog.py @ 1

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

Building directory structure

File size: 7.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
9schema = BaseFolderSchema +  Schema((
10    StringField('id',
11                required=0, ## Still actually required, but
12                            ## the widget will supply the missing value
13                            ## on non-submits
14                mode="rw",
15                accessor="getId",
16                mutator="setId",
17                default=None,
18                widget=IdWidget(label="Short Name",
19                                label_msgid="label_short_name",
20                                description="Should not contain spaces, underscores or mixed case. "\
21                                            "Short Name is part of the item's web address.",
22                                description_msgid="help_shortname",
23                                visible={'view' : 'visible'},
24                                i18n_domain="plone"),
25                ),
26    StringField('title',
27                required=1,
28                searchable=1,
29                default='',
30                accessor='Title',
31                widget=StringWidget(label_msgid="label_title",
32                                    description_msgid="help_title",
33                                    i18n_domain="plone"),
34                ),
35    StringField('description',
36                isMetadata=1,
37                accessor='Description',
38                searchable=1,               
39                widget=TextAreaWidget(label='Description', 
40                                      label_msgid="label_blog_description",
41                                      description_msgid="help_blog_description",
42                                      i18n_domain="SimpleBlog",
43                                      description='Give a description for this SimpleBlog.'),),
44    StringField('displayMode',
45                vocabulary=DISPLAY_MODE,
46                widget=SelectionWidget(label='Display Mode', 
47                                       label_msgid="label_display_mode",
48                                       description_msgid="help_display_mode",
49                                       i18n_domain="SimpleBlog",
50                                       description='Choose the display mode.'),
51                default='descriptionOnly'),
52    IntegerField('displayItems', 
53                widget=IntegerWidget(label='BlogEntries to display', 
54                                      label_msgid="label_display_items",
55                                      description_msgid="help_display_items",
56                                      i18n_domain="SimpleBlog",
57                                      description='Set the maximum number of BlogEntries to display.'), 
58                 default=20),
59    LinesField('categories',
60               widget=LinesWidget(label='Possible Categories', 
61                                  label_msgid="label_categories",
62                                  description_msgid="help_categories",
63                                  i18n_domain="SimpleBlog",
64                                  description='Supply the list of possible categories that can be used in SimpleBlog Entries.'),
65               ),
66    LinesField('tags',
67               mutator = 'setTags',
68               widget=LinesWidget(label="Tags",
69                                  description='List of tags.'),
70               ),
71    BooleanField('tagsEnabled',
72                  accessor = 'isTagsEnabled',
73                  default = 1,
74                  schemata = 'interface',
75                  widget = BooleanWidget(label='Enable technorati tags',
76                                     label_msgid="label_enable_tags",
77                                     description_msgid="help_enable_tags",),
78              ),
79    BooleanField('allowTrackback',
80                  default = 1,
81                  schemata = 'interface', 
82                  widget=BooleanWidget(label="Allow Trackback", 
83                                       label_msgid="label_allow_trackback",
84                                       description_msgid="help_allow_trackback",),
85               ),
86    StringField('adminEmail',
87                accessor = 'getAdminEmail',
88                mutator = 'setAdminEmail',
89                schemata = 'interface',
90                default = '',
91                widget=StringWidget(label="Administrator's email", 
92                                    label_msgid="label_adminEmail",
93                                    description_msgid="help_adminEmail",
94                                    i18n_domain="SimpleBlog",
95                                                    condition="python:0",
96                                    description="Enter administrator's email for receaving notification about blog's activity"),
97               )
98    #BooleanField('allowComments',
99    #              default = 1,
100    #              schemata = 'interface',
101    #              widget=BooleanWidget(label="Allow Comments",
102    #                                   label_msgid="label_allow_comments",
103    #                                   description_msgid="help_allow_comments",),
104    #           ),
105    #BooleanField('expandMainPageComments',
106    #              default = 0,
107    #              schemata = 'interface',
108    #              widget = BooleanWidget(label='Expand comments on main page',
109    #                                 label_msgid="label_expand_mainpage_comments",
110    #                                 description_msgid="help_expand_mainpage_comments",),
111    #          ),
112
113        ))
114
115
116class Blog(BaseFolder):
117    """
118Blog
119    """
120    allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet')
121    filter_content_types=1   
122    global_allow=1
123    schema=schema
124   
125    content_icon='simpleblog_icon.gif'
126
127    actions = ({'id': 'view',
128                'name': 'View',
129                'action': 'string:${object_url}/simpleblog_view',
130                'permissions': (CMFCorePermissions.View,) },
131        {'id': 'references',
132          'name': 'References',
133          'action': 'string:${object_url}/reference_edit',
134          'permissions': (CMFCorePermissions.ModifyPortalContent,),
135          'visible':0},
136        {'id': 'metadata',
137          'name': 'Properties',
138          'action': 'string:${object_url}/base_metadata',
139          'permissions': (CMFCorePermissions.ModifyPortalContent,),
140          'visible':0})
141
142    def manage_afterAdd(self, item, container):
143        BaseFolder.manage_afterAdd(self, item, container)
144        if self.simpleblog_tool.getCreatePortletOnBlogCreation():
145            if not hasattr(item.aq_base, 'right_slots'):
146                item._setProperty('right_slots', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines')
147            if not hasattr(item.aq_base, 'column_two_portlets'):
148                item._setProperty('column_two_portlets', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines')
149
150    def synContentValues(self):
151        # get brains for items that are published within the context of this blog.
152        entries = self.simpleblog_tool.searchForEntries(self, maxResults=0)
153
154        # convert to objects
155        objs = [e.getObject() for e in entries]
156        return objs
157
158    def setTags(self, value, **kwargs):
159        """ Save tags in lower case """
160        value = unique(value)
161        value.sort(lambda x, y: cmp(x,y))
162        self.getField('tags').set(self, value, **kwargs)
163
164    def getAdminEmail(self):
165        """ return blog admin email or root email """
166        val = self.getField('adminEmail').get(self)
167        if not val:
168            purl = getToolByName(self, 'portal_url')
169            val = purl.getPortalObject().getProperty("trackback_notification_email", "")
170        return val
171
172registerType(Blog)
173
Note: See TracBrowser for help on using the repository browser.