1 from Products.CMFCore.utils import getToolByName
2 from Acquisition import aq_base
4 from Products.Archetypes.event import ObjectInitializedEvent
13 def makePublicObject(container, type_name, id, **kw):
14 """Create an object in CONTAINER with type TYPE_NAME and id ID. Additional keyword args
15 specify additional factory arguments. After creation, the object is published if needed."""
16 id = container.invokeFactory(id=id, type_name=type_name, **kw)
17 ob = getattr(container,id)
18 event.notify(ObjectInitializedEvent(ob))
19 ob.at_post_create_script()
20 # if hasattr(aq_base(ob), 'manage_afterPortalFactoryCreate'):
21 # ob.manage_afterPortalFactoryCreate()
22 wf = getToolByName(container, 'portal_workflow')
23 if wf.getInfoFor(ob,'review_state','') != 'published':
24 wf.doActionFor(ob,'publish',comment='site setup')
27 def siteSetup(context):
29 if context.readDataFile('koehsel.policy_setup.txt') is None:
32 site = context.getSite()
33 qi = getToolByName(site, 'portal_quickinstaller')
34 wf = getToolByName(site, 'portal_workflow')
36 # Install EasyShop product
38 for p in INSTALL_PRODUCTS:
39 if not qi.isProductInstalled(p):
42 # Add and publish shop instance
45 except AttributeError:
46 makePublicObject(container=site, type_name='EasyShop',
47 id='shop', title='Shop', shopOwner='admin')
49 # Hide Users, News and Events
51 for id in ('Members', 'news', 'events'):
53 if wf.getInfoFor(ob,'review_state','') != 'private':
54 wf.doActionFor(ob,'retract',comment='site setup')
57 def contentSetup(app):
58 app.manage_addProduct['CMFPlone'].addPloneSite(id='site',
59 extension_ids=['koehsel.policy:default'])
62 # Called via hackery in __init__.py on every site start
65 except AttributeError:
67 from Testing.makerequest import makerequest
68 from AccessControl.SecurityManagement import newSecurityManager
69 import transaction, AccessControl
71 # Call 'contentSetup' as SITE_OWNER user with a valid REQUEST
72 req = makerequest(app)
73 newSecurityManager(req.REQUEST, app.acl_users.getUser(SITE_OWNER).__of__(app.acl_users))
76 newSecurityManager(None, AccessControl.User.system)