1 | from Products.Archetypes.public import listTypes |
---|
2 | from Products.Archetypes.Extensions.utils import installTypes, install_subskin |
---|
3 | from Products.CMFCore.utils import getToolByName |
---|
4 | from StringIO import StringIO |
---|
5 | from Products.CMFCore.CMFCorePermissions import setDefaultRoles |
---|
6 | |
---|
7 | from Products.SimpleBlog.config import * |
---|
8 | |
---|
9 | from Products.SimpleBlog import MetaWeblogAPI |
---|
10 | from Products.SimpleBlog import BloggerAPI |
---|
11 | from Products.SimpleBlog import MovableTypeAPI |
---|
12 | |
---|
13 | portlets=['here/portlet_simpleblog/macros/portletBlogFull_local', |
---|
14 | 'here/portlet_simpleblog/macros/portletBlogFull_global', |
---|
15 | 'here/portlet_simpleblog/macros/portletBlogRecent_local', |
---|
16 | 'here/portlet_simpleblog/macros/portletBlogRecent_global'] |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | def install(self): |
---|
21 | |
---|
22 | out = StringIO() |
---|
23 | |
---|
24 | installTypes(self, out, |
---|
25 | listTypes(PROJECTNAME), |
---|
26 | PROJECTNAME) |
---|
27 | |
---|
28 | install_subskin(self, out, GLOBALS) |
---|
29 | |
---|
30 | portal = getToolByName(self,'portal_url').getPortalObject() |
---|
31 | |
---|
32 | if not hasattr(self, 'simpleblog_tool'): |
---|
33 | addTool = portal.manage_addProduct['SimpleBlog'].manage_addTool |
---|
34 | addTool(type='SimpleBlog manager') |
---|
35 | |
---|
36 | #register the folderish items in portal_properties/site_properties for folder-contents views etc |
---|
37 | site_props = getToolByName(self, 'portal_properties').site_properties |
---|
38 | use_folder_tabs = site_props.getProperty('use_folder_tabs') |
---|
39 | if not 'Blog' in use_folder_tabs: |
---|
40 | site_props._updateProperty('use_folder_tabs', tuple(use_folder_tabs) + ('Blog','BlogFolder','BlogEntry')) |
---|
41 | |
---|
42 | # check for property use_folder_contents. This property seems not to be always there: |
---|
43 | if not site_props.hasProperty('use_folder_contents'): |
---|
44 | site_props.manage_addProperty('use_folder_contents', '', 'lines') |
---|
45 | |
---|
46 | use_folder_contents = site_props.getProperty('use_folder_contents') |
---|
47 | if not 'Blog' in use_folder_contents: |
---|
48 | site_props._updateProperty('use_folder_contents', tuple(use_folder_contents) + ('Blog','BlogFolder', 'BlogEntry')) |
---|
49 | |
---|
50 | # discussion enabled by default for BlogEntries |
---|
51 | getToolByName(self, 'portal_types').BlogEntry.allow_discussion=1 |
---|
52 | |
---|
53 | # register 2.0 control panel |
---|
54 | try: |
---|
55 | cp=self.portal_controlpanel |
---|
56 | cp.addAction(id='SimpleBlogSetup', |
---|
57 | name='SimpleBlog Setup', |
---|
58 | action='string:${portal_url}/prefs_simpleblog_form', |
---|
59 | permission='Manage portal', |
---|
60 | category='Products', |
---|
61 | appId='SimpleBlog', |
---|
62 | imageUrl='SimpleBlog/simpleblog_icon.gif', |
---|
63 | description='Configure SimpleBlog global settings') |
---|
64 | except: |
---|
65 | pass |
---|
66 | |
---|
67 | from Products.SimpleBlog import SimpleBlogWorkflow |
---|
68 | reload(SimpleBlogWorkflow) |
---|
69 | |
---|
70 | # Remove workflows for BlogEntry and BlogFolder |
---|
71 | wf_tool = getToolByName(self, 'portal_workflow') |
---|
72 | wf_tool.setChainForPortalTypes( ('Blog', 'BlogEntry','BlogFolder'), []) |
---|
73 | |
---|
74 | add_workflow(self, 'simpleblog_workflow', 'simpleblog_workflow (Workflow for Blog Entries)', ('BlogEntry',), out) |
---|
75 | wf_tool.setChainForPortalTypes(('Blog','BlogFolder'), 'folder_workflow') |
---|
76 | |
---|
77 | from Products.SimpleBlog import TrackbackWorkflow |
---|
78 | reload(TrackbackWorkflow) |
---|
79 | |
---|
80 | add_workflow(self, 'trackback_workflow', 'trackback_workflow (TrackBack Workflow)', ('TrackBack',), out) |
---|
81 | wf_tool.setChainForPortalTypes( ('TrackBack'), 'trackback_workflow') |
---|
82 | |
---|
83 | # Create an RPCAuth if there is not one already |
---|
84 | installRPCAuth(self) |
---|
85 | RPCAuth = self.simpleblog_tool.findRPCAuth(self) |
---|
86 | |
---|
87 | # add the blogger object to the portal's root |
---|
88 | # Setup the MetaWeblog API |
---|
89 | portal.metaWeblog = MetaWeblogAPI.MetaWeblogAPI().__of__(self) |
---|
90 | portal.metaWeblog.setupRPCAuth(RPCAuth) |
---|
91 | |
---|
92 | # Setup the Blogger API |
---|
93 | portal.blogger = BloggerAPI.BloggerAPI().__of__(self) |
---|
94 | portal.blogger.setupRPCAuth(RPCAuth) |
---|
95 | |
---|
96 | # Setup the MovableTypeAPI API |
---|
97 | portal.mt = MovableTypeAPI.MovableTypeAPI().__of__(self) |
---|
98 | portal.mt.setupRPCAuth(RPCAuth) |
---|
99 | |
---|
100 | print >> out, "Successfully installed %s." % PROJECTNAME |
---|
101 | return out.getvalue() |
---|
102 | |
---|
103 | def add_workflow(self, wf_id, wf_factory_id, types, out): |
---|
104 | """ add a workflow definition to the portal_workflow tool """ |
---|
105 | wf_tool = self.portal_workflow |
---|
106 | try: |
---|
107 | wf_tool.manage_delObjects([wf_id]) |
---|
108 | out.write('Removed existant workflow "%s"\n'%wf_id) |
---|
109 | except: |
---|
110 | pass |
---|
111 | wf_tool.manage_addWorkflow(wf_factory_id, wf_id) |
---|
112 | if types: |
---|
113 | wf_tool.setChainForPortalTypes(types, wf_id) |
---|
114 | out.write('Added workflow "%s"\n'%wf_id) |
---|
115 | |
---|
116 | def installRPCAuth(self): |
---|
117 | if not hasattr(self, 'RPCAuth'): |
---|
118 | try: |
---|
119 | self.manage_addProduct['RPCAuth'].manage_addRPCAuth('RPCAuth') |
---|
120 | except: |
---|
121 | raise "An RPCAuth instance could not be created. Please make sure RPCAuth is installed correctly." |
---|
122 | |
---|
123 | |
---|
124 | def uninstall(self): |
---|
125 | # remove the references in each folder to our portlet: |
---|
126 | |
---|
127 | # this gotta be effective some time |
---|
128 | # someone's gotta test if this works like it should |
---|
129 | # commented out for the time being: |
---|
130 | |
---|
131 | #portal = getToolByName(self,'portal_url').getPortalObject() |
---|
132 | #processPortletOld(portal) |
---|
133 | #processPortletNew(portal) |
---|
134 | #removeReferences(portal) |
---|
135 | |
---|
136 | #remove configlet |
---|
137 | try: |
---|
138 | self.portal_controlpanel.unregisterApplication('SimpleBlog') |
---|
139 | except: |
---|
140 | pass |
---|
141 | |
---|
142 | def removeReferences(obj): |
---|
143 | for o in obj.contentValues(): |
---|
144 | if o.isPrincipiaFolderish: |
---|
145 | processPortletOld(o) |
---|
146 | processPortletNew(o) |
---|
147 | removeReferences(o) |
---|
148 | |
---|
149 | def processPortletOld(o): |
---|
150 | if not o.portal_type in ['Blog', 'BlogFolder', 'BlogEntry']: |
---|
151 | if hasattr(o.aq_base, 'left_slots') or hasattr(o.aq_base, 'right_slots'): |
---|
152 | new=[] |
---|
153 | if hasattr(o.aq_base,'left_slots'): |
---|
154 | for l in o.aq_base.left_slots: |
---|
155 | if not l in portlets: |
---|
156 | new.append(l) |
---|
157 | o.left_slots=new |
---|
158 | new=[] |
---|
159 | if hasattr(o.aq_base, 'right_slots'): |
---|
160 | for l in o.aq_base.right_slots: |
---|
161 | if not l in portlets: |
---|
162 | new.append(l) |
---|
163 | o.right_slots=new |
---|
164 | |
---|
165 | def processPortletNew(o): |
---|
166 | if not o.portal_type in ['Blog', 'BlogFolder', 'BlogEntry']: |
---|
167 | if hasattr(o.aq_base, 'column_one_portlets') or hasattr(o.aq_base, 'column_two_portlets'): |
---|
168 | new=[] |
---|
169 | if hasattr(o.aq_base,'column_one_portlets'): |
---|
170 | for l in o.aq_base.column_one_portlets: |
---|
171 | if not l in portlets: |
---|
172 | new.append(l) |
---|
173 | o.column_one_portlets=new |
---|
174 | new=[] |
---|
175 | if hasattr(o.aq_base, 'column_two_portlets'): |
---|
176 | for l in o.aq_base.column_two_portlets: |
---|
177 | if not l in portlets: |
---|
178 | new.append(l) |
---|
179 | o.column_two_portlets=new |
---|