1 | from Products.Archetypes.public import * |
---|
2 | from Products.Archetypes.utils import unique |
---|
3 | from Products.CMFCore import CMFCorePermissions |
---|
4 | from DateTime import DateTime |
---|
5 | from config import DISPLAY_MODE |
---|
6 | import Permissions |
---|
7 | from Products.CMFCore.utils import getToolByName |
---|
8 | |
---|
9 | schema = 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 | # used to be new trackbaks notification email address |
---|
87 | StringField('adminEmail', |
---|
88 | accessor = 'getAdminEmail', |
---|
89 | mutator = 'setAdminEmail', |
---|
90 | schemata = 'interface', |
---|
91 | default = '', |
---|
92 | widget=StringWidget(label="Administrator's email", |
---|
93 | label_msgid="label_adminEmail", |
---|
94 | description_msgid="help_adminEmail", |
---|
95 | i18n_domain="SimpleBlog", |
---|
96 | condition="python:0", # this line have to be removed in order to be visible/editable |
---|
97 | description="Enter administrator's email for receaving notification about blog's activity"), |
---|
98 | ) |
---|
99 | #BooleanField('allowComments', |
---|
100 | # default = 1, |
---|
101 | # schemata = 'interface', |
---|
102 | # widget=BooleanWidget(label="Allow Comments", |
---|
103 | # label_msgid="label_allow_comments", |
---|
104 | # description_msgid="help_allow_comments",), |
---|
105 | # ), |
---|
106 | #BooleanField('expandMainPageComments', |
---|
107 | # default = 0, |
---|
108 | # schemata = 'interface', |
---|
109 | # widget = BooleanWidget(label='Expand comments on main page', |
---|
110 | # label_msgid="label_expand_mainpage_comments", |
---|
111 | # description_msgid="help_expand_mainpage_comments",), |
---|
112 | # ), |
---|
113 | |
---|
114 | )) |
---|
115 | |
---|
116 | |
---|
117 | class Blog(BaseFolder): |
---|
118 | """ |
---|
119 | Blog |
---|
120 | """ |
---|
121 | allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet') |
---|
122 | filter_content_types=1 |
---|
123 | global_allow=1 |
---|
124 | schema=schema |
---|
125 | |
---|
126 | content_icon='simpleblog_icon.gif' |
---|
127 | |
---|
128 | actions = ({'id': 'view', |
---|
129 | 'name': 'View', |
---|
130 | 'action': 'string:${object_url}/simpleblog_view', |
---|
131 | 'permissions': (CMFCorePermissions.View,) }, |
---|
132 | {'id': 'references', |
---|
133 | 'name': 'References', |
---|
134 | 'action': 'string:${object_url}/reference_edit', |
---|
135 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
136 | 'visible':0}, |
---|
137 | {'id': 'metadata', |
---|
138 | 'name': 'Properties', |
---|
139 | 'action': 'string:${object_url}/base_metadata', |
---|
140 | 'permissions': (CMFCorePermissions.ModifyPortalContent,), |
---|
141 | 'visible':0}) |
---|
142 | |
---|
143 | def manage_afterAdd(self, item, container): |
---|
144 | BaseFolder.manage_afterAdd(self, item, container) |
---|
145 | if self.simpleblog_tool.getCreatePortletOnBlogCreation(): |
---|
146 | if not hasattr(item.aq_base, 'right_slots'): |
---|
147 | item._setProperty('right_slots', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines') |
---|
148 | if not hasattr(item.aq_base, 'column_two_portlets'): |
---|
149 | item._setProperty('column_two_portlets', ['here/portlet_simpleblog/macros/portletBlogFull_local'], 'lines') |
---|
150 | |
---|
151 | def synContentValues(self): |
---|
152 | # get brains for items that are published within the context of this blog. |
---|
153 | entries = self.simpleblog_tool.searchForEntries(self, maxResults=0) |
---|
154 | |
---|
155 | # convert to objects |
---|
156 | objs = [e.getObject() for e in entries] |
---|
157 | return objs |
---|
158 | |
---|
159 | def setTags(self, value, **kwargs): |
---|
160 | """ Save tags in lower case """ |
---|
161 | value = unique(value) |
---|
162 | value.sort(lambda x, y: cmp(x,y)) |
---|
163 | self.getField('tags').set(self, value, **kwargs) |
---|
164 | |
---|
165 | def getAdminEmail(self): |
---|
166 | """ return blog admin email or root email """ |
---|
167 | val = self.getField('adminEmail').get(self) |
---|
168 | if not val: |
---|
169 | purl = getToolByName(self, 'portal_url') |
---|
170 | val = purl.getPortalObject().getProperty("trackback_notification_email", "") |
---|
171 | return val |
---|
172 | |
---|
173 | registerType(Blog) |
---|
174 | |
---|