22b3a87aace47fbbae5bfcdadd98fbdc10883973
[zope-bootstrap.git] / src / koehsel.policy / koehsel / policy / setuphandlers.py
1 from Products.CMFCore.utils import getToolByName
2
3 INSTALL_PRODUCTS = ['easyshop.core']
4
5 def siteSetup(context):
6
7     if context.readDataFile('koehsel.policy_setup.txt') is None:
8         return
9
10     site = context.getSite()
11
12     # Install EasyShop product
13
14     qi = getToolByName(site, 'portal_quickinstaller')
15     for p in INSTALL_PRODUCTS:
16         if not qi.isProductInstalled(p):
17             qi.installProduct(p)
18
19     # Add and publish shop instance
20
21     try: site.shop
22     except AttributeError:
23         site.invokeFactory(id='shop', type_name='EasyShop')
24         shop = site.shop
25         shop.title = 'Shop'
26         shop.shopOwner = 'admin'
27         wf = getToolByName(site, 'portal_workflow')    
28         if wf.getInfoFor(shop,'review_state','') != 'published':
29             wf.doActionFor(shop,'publish',comment='site setup')
30
31     # Hide Users, News and Events
32
33     for id in ('Members', 'news', 'events'):
34         ob = getattr(site,id)
35         if wf.getInfoFor(ob,'review_state','') != 'private':
36             wf.doActionFor(ob,'retract',comment='site setup')
37
38
39 # Called via hackery in __init__.py
40 def appInit(app):
41     try: app.site
42     except AttributeError:
43         app.manage_addProduct['CMFPlone'].addPloneSite(id='site',
44                                                        extension_ids=['koehsel.policy:default'])