source: products/SimpleBlog/branches/plone-2.5/Extensions/Install.py

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

Building directory structure

  • Property svn:eol-style set to native
File size: 8.1 KB
Line 
1from Products.Archetypes.public import listTypes
2from Products.Archetypes.Extensions.utils import installTypes, install_subskin
3from Products.CMFCore.utils import getToolByName
4from StringIO import StringIO
5from Products.CMFCore.CMFCorePermissions import setDefaultRoles
6from Products.CMFDynamicViewFTI.migrate import migrateFTIs
7from Products.SimpleBlog.config import *
8
9portlets=['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
14def install(self):
15
16    out = StringIO()
17
18    installTypes(self, out,
19                 listTypes(PROJECTNAME),
20                 PROJECTNAME)
21
22    install_subskin(self, out, GLOBALS)
23
24    # Migrate FTI, to make sure we get the necessary infrastructure for the
25    # 'display' menu to work.
26    migrated = migrateFTIs(self, product=PROJECTNAME)
27    print >>out, "Switched to DynamicViewFTI: %s" % ', '.join(migrated)
28
29    # Enable portal_factory
30    factory = getToolByName(self, 'portal_factory')
31    types = factory.getFactoryTypes().keys()
32    if 'TrackBack' not in types:
33        types.append('TrackBack')
34        factory.manage_setPortalFactoryTypes(listOfTypeIds = types)
35    if 'BlogEntry' not in types:
36        types.append('BlogEntry')
37        factory.manage_setPortalFactoryTypes(listOfTypeIds = types)
38    if 'BlogFolder' not in types:
39        types.append('BlogFolder')
40        factory.manage_setPortalFactoryTypes(listOfTypeIds = types)
41    if 'Blog' not in types:
42        types.append('Blog')
43        factory.manage_setPortalFactoryTypes(listOfTypeIds = types)
44
45    portal = getToolByName(self,'portal_url').getPortalObject()
46
47    if not hasattr(self, 'simpleblog_tool'):
48        addTool = portal.manage_addProduct['SimpleBlog'].manage_addTool
49        addTool(type='SimpleBlog manager')   
50   
51    # register the css
52    # Install stylesheet
53    # Make it work for the entire portal because the portlets can
54    # be used everywhere
55    portal_css = getToolByName(self, 'portal_css')
56    portal_css.manage_addStylesheet(id = 'SimpleBlogCSS.css',
57                                    expression = '',
58                                    media = 'all',
59                                    title = 'SimpleBlog styles',
60                                    enabled = True)   
61   
62    #register the folderish items in portal_properties/site_properties for folder-contents views etc
63    site_props = getToolByName(self, 'portal_properties').site_properties
64   
65    use_folder_tabs = site_props.getProperty('use_folder_tabs')
66    if not 'Blog' in use_folder_tabs:
67        site_props._updateProperty('use_folder_tabs', tuple(use_folder_tabs) + ('Blog','BlogFolder'))
68
69    use_folder_contents = site_props.getProperty('use_folder_contents')
70    if not 'Blog' in use_folder_contents:
71        site_props._updateProperty('use_folder_contents', tuple(use_folder_contents) + ('Blog','BlogFolder'))
72
73    if ENTRY_IS_FOLDERISH:
74        if not 'BlogEntry' in use_folder_tabs:
75            site_props._updateProperty('use_folder_tabs', tuple(use_folder_tabs) + ('BlogEntry',))
76        if not 'BlogEntry' in use_folder_contents:
77            site_props._updateProperty('use_folder_contents', tuple(use_folder_contents) + ('BlogEntry',))
78       
79
80    #Make sure blog entries aren't shown in the navtree by default
81    nav_props = getToolByName(self, 'portal_properties').navtree_properties
82    metaTypesNotToList = nav_props.getProperty('metaTypesNotToList')
83    if not 'BlogEntry' in metaTypesNotToList:
84        nav_props._updateProperty('metaTypesNotToList', tuple(metaTypesNotToList) + ('BlogEntry',))
85       
86    # Add to default_page_types
87    # Allow people to have a Blog as the default page
88    propsTool = getToolByName(self, 'portal_properties')
89    siteProperties = getattr(propsTool, 'site_properties')   
90    defaultPageTypes = list(siteProperties.getProperty('default_page_types'))
91    if 'Blog' not in defaultPageTypes:
92        defaultPageTypes.append('Blog')
93    siteProperties.manage_changeProperties(default_page_types = defaultPageTypes)
94
95    if not portal.hasProperty('trackback_notification_email'):
96        portal.manage_addProperty('trackback_notification_email', '', 'string')
97
98    # discussion enabled by default for BlogEntries
99    getToolByName(self, 'portal_types').BlogEntry.allow_discussion=1
100
101    # register 2.0 control panel
102    try:
103        cp=self.portal_controlpanel
104        cp.addAction(id='SimpleBlogSetup',
105                     name='SimpleBlog Setup',
106                     action='string:${portal_url}/prefs_simpleblog_form',
107                     permission='Manage portal',
108                     category='Products',
109                     appId='SimpleBlog',
110                     imageUrl='simpleblog_icon.gif',
111                     description='Configure SimpleBlog global settings')
112    except:
113        pass
114
115    # install the workflow
116    from Products.SimpleBlog import SimpleBlogWorkflow, TrackbackWorkflow
117    reload(SimpleBlogWorkflow)
118    reload(TrackbackWorkflow)
119
120
121    # Remove workflows for BlogEntry and BlogFolder
122    wf_tool = getToolByName(self, 'portal_workflow')
123    wf_tool.setChainForPortalTypes( ('Blog', 'BlogEntry','BlogFolder'), []) 
124   
125    add_workflow(self, 'simpleblog_workflow', 'simpleblog_workflow (Workflow for Blog Entries)', ('BlogEntry',), out)
126    add_workflow(self, 'trackback_workflow', 'trackback_workflow (TrackBack Workflow)', ('TrackBack',), out)
127
128    wf_tool.setChainForPortalTypes(('Blog','BlogFolder'), 'folder_workflow')       
129
130    print >> out, "Successfully installed %s." % PROJECTNAME
131    return out.getvalue()
132
133def add_workflow(self, wf_id, wf_factory_id, types, out):
134    """ add a workflow definition to the portal_workflow tool """
135    wf_tool = self.portal_workflow
136    try:
137        wf_tool.manage_delObjects([wf_id])
138        out.write('Removed existant workflow "%s"\n'%wf_id)
139    except:
140        pass
141    wf_tool.manage_addWorkflow(wf_factory_id, wf_id)
142    if types:
143        wf_tool.setChainForPortalTypes(types, wf_id)
144    out.write('Added workflow "%s"\n'%wf_id)
145
146
147def uninstall(self):
148    # remove the references in each folder to our portlet:
149   
150    # this gotta be effective some time
151    # someone's gotta test if this works like it should
152    # commented out for the time being:
153   
154    #portal = getToolByName(self,'portal_url').getPortalObject()
155    #processPortletOld(portal)
156    #processPortletNew(portal)
157    #removeReferences(portal)
158   
159    #remove configlet
160    try:
161        self.portal_controlpanel.unregisterApplication('SimpleBlog')
162    except:
163        pass
164                     
165def removeReferences(obj):
166    for o in obj.contentValues():
167        if o.isPrincipiaFolderish:
168            processPortletOld(o)
169            processPortletNew(o)
170            removeReferences(o)
171
172def processPortletOld(o):
173    if not o.portal_type in ['Blog', 'BlogFolder', 'BlogEntry']:
174        if hasattr(o.aq_base, 'left_slots') or hasattr(o.aq_base, 'right_slots'):
175            new=[]
176            if hasattr(o.aq_base,'left_slots'):
177                for l in o.aq_base.left_slots:
178                    if not l in portlets:
179                        new.append(l)
180                o.left_slots=new
181            new=[]
182            if hasattr(o.aq_base, 'right_slots'):
183                for l in o.aq_base.right_slots:
184                    if not l in portlets:
185                        new.append(l)
186                o.right_slots=new
187
188def processPortletNew(o):
189    if not o.portal_type in ['Blog', 'BlogFolder', 'BlogEntry']:   
190        if hasattr(o.aq_base, 'column_one_portlets') or hasattr(o.aq_base, 'column_two_portlets'):
191            new=[]
192            if hasattr(o.aq_base,'column_one_portlets'):
193                for l in o.aq_base.column_one_portlets:
194                    if not l in portlets:
195                        new.append(l)
196                o.column_one_portlets=new
197            new=[]
198            if hasattr(o.aq_base, 'column_two_portlets'):
199                for l in o.aq_base.column_two_portlets:
200                    if not l in portlets:
201                        new.append(l)
202                o.column_two_portlets=new
203       
204           
Note: See TracBrowser for help on using the repository browser.