dc4596116b331d34ff3aa0e89ff8723f11ad98e8
[zope-bootstrap.git] / src / koehsel.policy / koehsel / policy / setuphandlers.py
1 from Products.CMFCore.utils import getToolByName
2
3 INSTALL_PRODUCTS = [
4     'easyshop.core', 
5     'koehsel.theme',
6 ]
7
8 SITE_OWNER = 'admin'
9
10 def siteSetup(context):
11
12     if context.readDataFile('koehsel.policy_setup.txt') is None:
13         return
14
15     site = context.getSite()
16     qi = getToolByName(site, 'portal_quickinstaller')
17     wf = getToolByName(site, 'portal_workflow')    
18
19     # Install EasyShop product
20
21     for p in INSTALL_PRODUCTS:
22         if not qi.isProductInstalled(p):
23             qi.installProduct(p)
24
25     # Add and publish shop instance
26
27     try: site.shop
28     except AttributeError:
29         site.invokeFactory(id='shop', type_name='EasyShop')
30         shop = site.shop
31         shop.title = 'Shop'
32         shop.shopOwner = 'admin'
33         if wf.getInfoFor(shop,'review_state','') != 'published':
34             wf.doActionFor(shop,'publish',comment='site setup')
35
36     # Hide Users, News and Events
37
38     for id in ('Members', 'news', 'events'):
39         ob = getattr(site,id)
40         if wf.getInfoFor(ob,'review_state','') != 'private':
41             wf.doActionFor(ob,'retract',comment='site setup')
42
43
44 def contentSetup(app):
45     app.manage_addProduct['CMFPlone'].addPloneSite(id='site',
46                                                    extension_ids=['koehsel.policy:default'])
47
48
49 # Called via hackery in __init__.py on every site start
50 def appInit(app):
51     try: app.site
52     except AttributeError:
53
54         from Testing.makerequest import makerequest
55         from AccessControl.SecurityManagement import newSecurityManager
56         import transaction, AccessControl
57
58         # Call 'contentSetup' as SITE_OWNER user with a valid REQUEST
59         req = makerequest(app)
60         newSecurityManager(req.REQUEST, app.acl_users.getUser(SITE_OWNER).__of__(app.acl_users))
61         contentSetup(req)
62         transaction.commit()
63         newSecurityManager(None, AccessControl.User.system)