[1] | 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 | portlets=['here/portlet_simpleblog/macros/portletBlogFull_local', |
---|
| 10 | 'here/portlet_simpleblog/macros/portletBlogFull_global', |
---|
| 11 | 'here/portlet_simpleblog/macros/portletBlogRecent_local', |
---|
| 12 | 'here/portlet_simpleblog/macros/portletBlogRecent_global'] |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | def install(self): |
---|
| 18 | |
---|
| 19 | out = StringIO() |
---|
| 20 | |
---|
| 21 | installTypes(self, out, |
---|
| 22 | listTypes(PROJECTNAME), |
---|
| 23 | PROJECTNAME) |
---|
| 24 | |
---|
| 25 | install_subskin(self, out, GLOBALS) |
---|
| 26 | |
---|
| 27 | portal = getToolByName(self,'portal_url').getPortalObject() |
---|
| 28 | |
---|
| 29 | if not hasattr(self, 'simpleblog_tool'): |
---|
| 30 | addTool = portal.manage_addProduct['SimpleBlog'].manage_addTool |
---|
| 31 | addTool(type='SimpleBlog manager') |
---|
| 32 | |
---|
| 33 | #register the folderish items in portal_properties/site_properties for folder-contents views etc |
---|
| 34 | site_props = getToolByName(self, 'portal_properties').site_properties |
---|
| 35 | use_folder_tabs = site_props.getProperty('use_folder_tabs') |
---|
| 36 | if not 'Blog' in use_folder_tabs: |
---|
| 37 | site_props._updateProperty('use_folder_tabs', tuple(use_folder_tabs) + ('Blog','BlogFolder','BlogEntry')) |
---|
| 38 | |
---|
| 39 | if not portal.hasProperty('trackback_notification_email'): |
---|
| 40 | portal.manage_addProperty('trackback_notification_email', '', 'string') |
---|
| 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 | print >> out, "Successfully installed %s." % PROJECTNAME |
---|
| 84 | return out.getvalue() |
---|
| 85 | |
---|
| 86 | def add_workflow(self, wf_id, wf_factory_id, types, out): |
---|
| 87 | """ add a workflow definition to the portal_workflow tool """ |
---|
| 88 | wf_tool = self.portal_workflow |
---|
| 89 | try: |
---|
| 90 | wf_tool.manage_delObjects([wf_id]) |
---|
| 91 | out.write('Removed existant workflow "%s"\n'%wf_id) |
---|
| 92 | except: |
---|
| 93 | pass |
---|
| 94 | wf_tool.manage_addWorkflow(wf_factory_id, wf_id) |
---|
| 95 | if types: |
---|
| 96 | wf_tool.setChainForPortalTypes(types, wf_id) |
---|
| 97 | out.write('Added workflow "%s"\n'%wf_id) |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | def uninstall(self): |
---|
| 101 | # remove the references in each folder to our portlet: |
---|
| 102 | |
---|
| 103 | # this gotta be effective some time |
---|
| 104 | # someone's gotta test if this works like it should |
---|
| 105 | # commented out for the time being: |
---|
| 106 | |
---|
| 107 | #portal = getToolByName(self,'portal_url').getPortalObject() |
---|
| 108 | #processPortletOld(portal) |
---|
| 109 | #processPortletNew(portal) |
---|
| 110 | #removeReferences(portal) |
---|
| 111 | |
---|
| 112 | #remove configlet |
---|
| 113 | try: |
---|
| 114 | self.portal_controlpanel.unregisterApplication('SimpleBlog') |
---|
| 115 | except: |
---|
| 116 | pass |
---|
| 117 | |
---|
| 118 | def removeReferences(obj): |
---|
| 119 | for o in obj.contentValues(): |
---|
| 120 | if o.isPrincipiaFolderish: |
---|
| 121 | processPortletOld(o) |
---|
| 122 | processPortletNew(o) |
---|
| 123 | removeReferences(o) |
---|
| 124 | |
---|
| 125 | def processPortletOld(o): |
---|
| 126 | if not o.portal_type in ['Blog', 'BlogFolder', 'BlogEntry']: |
---|
| 127 | if hasattr(o.aq_base, 'left_slots') or hasattr(o.aq_base, 'right_slots'): |
---|
| 128 | new=[] |
---|
| 129 | if hasattr(o.aq_base,'left_slots'): |
---|
| 130 | for l in o.aq_base.left_slots: |
---|
| 131 | if not l in portlets: |
---|
| 132 | new.append(l) |
---|
| 133 | o.left_slots=new |
---|
| 134 | new=[] |
---|
| 135 | if hasattr(o.aq_base, 'right_slots'): |
---|
| 136 | for l in o.aq_base.right_slots: |
---|
| 137 | if not l in portlets: |
---|
| 138 | new.append(l) |
---|
| 139 | o.right_slots=new |
---|
| 140 | |
---|
| 141 | def processPortletNew(o): |
---|
| 142 | if not o.portal_type in ['Blog', 'BlogFolder', 'BlogEntry']: |
---|
| 143 | if hasattr(o.aq_base, 'column_one_portlets') or hasattr(o.aq_base, 'column_two_portlets'): |
---|
| 144 | new=[] |
---|
| 145 | if hasattr(o.aq_base,'column_one_portlets'): |
---|
| 146 | for l in o.aq_base.column_one_portlets: |
---|
| 147 | if not l in portlets: |
---|
| 148 | new.append(l) |
---|
| 149 | o.column_one_portlets=new |
---|
| 150 | new=[] |
---|
| 151 | if hasattr(o.aq_base, 'column_two_portlets'): |
---|
| 152 | for l in o.aq_base.column_two_portlets: |
---|
| 153 | if not l in portlets: |
---|
| 154 | new.append(l) |
---|
| 155 | o.column_two_portlets=new |
---|
| 156 | |
---|
| 157 | |
---|