1 from Products.CMFCore.utils import getToolByName
2 from Acquisition import aq_base
4 from Products.Archetypes.event import ObjectInitializedEvent
5 from plone.app.controlpanel.security import SecurityControlPanelAdapter
14 def makeObject(container, type_name, id, **kw):
15 """Create an object in CONTAINER with type TYPE_NAME and id ID. Additional keyword args
16 specify additional factory arguments. After creation, the object is published if needed."""
17 id = container.invokeFactory(id=id, type_name=type_name, **kw)
18 ob = getattr(container,id)
19 event.notify(ObjectInitializedEvent(ob))
20 if hasattr(aq_base(ob), 'at_post_create_script'):
21 ob.at_post_create_script()
22 if hasattr(aq_base(ob), 'manage_afterPortalFactoryCreate'):
23 ob.manage_afterPortalFactoryCreate()
27 def siteSetup(context):
29 if context.readDataFile('koehsel.policy_setup.txt') is None:
32 site = context.getSite()
33 qi = getToolByName(site, 'portal_quickinstaller')
35 # Install EasyShop product
37 for p in INSTALL_PRODUCTS:
38 if not qi.isProductInstalled(p):
41 # Enable Self-Registration
43 scpa = SecurityControlPanelAdapter(site)
44 scpa.set_enable_self_reg(True)
46 # If not already installed, initialize development content
49 except AttributeError:
50 siteSetupContent(site)
53 def siteSetupContent(site):
55 wf = getToolByName(site, 'portal_workflow')
57 # Change front-page stuff
59 fp = getattr(site,'front-page')
60 fp.setTitle("Startsteite")
63 fp.setPresentation(False)
66 # Create easy-shop instance
68 shop = makeObject(container=site, type_name='EasyShop', id='shop',
69 title='Shop', shopOwner='admin')
71 if wf.getInfoFor(shop,'review_state','') != 'published':
72 wf.doActionFor(shop,'publish',comment='site setup')
74 # Hide Users, News and Events
76 for id in ('Members', 'news', 'events'):
78 if wf.getInfoFor(ob,'review_state','') != 'private':
79 wf.doActionFor(ob,'retract',comment='site setup')
83 mt = getToolByName(site,'portal_membership')
84 mt.addMember('shop','shop',[],[])
85 member = mt.getMemberById('shop')
86 member.setMemberProperties({'fullname': 'Shop Testuser'})
89 def contentSetup(app):
90 app.manage_addProduct['CMFPlone'].addPloneSite(id='site',
91 extension_ids=['koehsel.policy:default'])
94 # Called via hackery in __init__.py on every site start
97 except AttributeError:
99 from Testing.makerequest import makerequest
100 from AccessControl.SecurityManagement import newSecurityManager
101 import transaction, AccessControl
103 # Call 'contentSetup' as SITE_OWNER user with a valid REQUEST
104 req = makerequest(app)
105 newSecurityManager(req.REQUEST, app.acl_users.getUserById(SITE_OWNER).__of__(app.acl_users))
108 newSecurityManager(None, AccessControl.User.system)