Auto-create initial PloneSite instance on zope startup
Stefan Bund [Wed, 21 Oct 2009 09:24:45 +0000 (11:24 +0200)]
.gitignore
Makefile.master
src/koehsel.policy/koehsel.policy.egg-info/SOURCES.txt [deleted file]
src/koehsel.policy/koehsel/policy/__init__.py
src/koehsel.policy/koehsel/policy/configure.zcml
src/koehsel.policy/koehsel/policy/profiles.zcml [new file with mode: 0644]
src/koehsel.policy/koehsel/policy/profiles/default/koehsel.policy_setup.txt [new file with mode: 0644]
src/koehsel.policy/koehsel/policy/profiles/default/metadata.xml
src/koehsel.policy/koehsel/policy/setuphandlers.py
src/koehsel.theme/koehsel.theme.egg-info/SOURCES.txt [deleted file]

index 7513caf..cfb4c87 100644 (file)
@@ -11,3 +11,4 @@ parts/
 *.pyc
 easyshop/
 /local.cfg
+SOURCES.txt
index 19e6634..6d9a7f6 100644 (file)
@@ -80,7 +80,7 @@ bootstrap:
 shell:
        @PATH=$(BASEDIR)/$(PYTHON_DIR)/bin:$(BASEDIR)/bin:$$PATH $$SHELL
 
-init: python setuptools pil eggs buildout bootstrap otherinit update .gitignore
+init: python setuptools pil eggs buildout otherinit otherupdate bootstrap update .gitignore
 
 otherinit::
 
diff --git a/src/koehsel.policy/koehsel.policy.egg-info/SOURCES.txt b/src/koehsel.policy/koehsel.policy.egg-info/SOURCES.txt
deleted file mode 100644 (file)
index 06f823e..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-README.txt
-setup.cfg
-setup.py
-koehsel/__init__.py
-koehsel.policy.egg-info/PKG-INFO
-koehsel.policy.egg-info/SOURCES.txt
-koehsel.policy.egg-info/dependency_links.txt
-koehsel.policy.egg-info/entry_points.txt
-koehsel.policy.egg-info/namespace_packages.txt
-koehsel.policy.egg-info/not-zip-safe
-koehsel.policy.egg-info/paster_plugins.txt
-koehsel.policy.egg-info/requires.txt
-koehsel.policy.egg-info/top_level.txt
-koehsel/policy/__init__.py
-koehsel/policy/setuphandlers.py
-koehsel/policy/tests.py
\ No newline at end of file
index 52f45a0..b5e70dc 100644 (file)
@@ -1,3 +1,30 @@
+import setuphandlers
+import OFS.Application
+from App.Product import doInstall
+import transaction
+from AccessControl.SecurityManagement import newSecurityManager
+import AccessControl
+from Testing.makerequest import makerequest
+
+orig_install_standards = None
+
+def install_standards(app):
+    orig_install_standards(app)
+    transaction.commit()
+
+    # Log in as 'admin' user
+    newSecurityManager(None, app.acl_users.getUser('admin'))
+    setuphandlers.appInit(makerequest(app))
+    transaction.commit()
+
+    # Back to system user
+    newSecurityManager(None, AccessControl.User.system)
+
 
 def initialize(context):
     """Initializer called when used as a Zope 2 product."""
+    global orig_install_standards
+
+    if doInstall():
+        orig_install_standards = OFS.Application.install_standards
+        OFS.Application.install_standards = install_standards
index 56160c0..ab82b3b 100644 (file)
@@ -5,20 +5,6 @@
     i18n_domain="koehsel.policy">
 
   <five:registerPackage package="." initialize=".initialize" />
-
-  <genericsetup:registerProfile
-      name="default"
-      title="Koehsel Site"
-      directory="profiles/default"
-      description='Extension profile for the Koehsel Site.'
-      provides="Products.GenericSetup.interfaces.EXTENSION"
-      />
-
-  <genericsetup:importStep
-      name="koehsel.policy.various"
-      title="Koehsel Theme: miscellaneous import steps"
-      description="Various import steps that are not handled by GS import/export handlers."
-      handler="koehsel.policy.setuphandlers.setupVarious">
-  </genericsetup:importStep>
+  <include file="profiles.zcml" />
 
 </configure>
diff --git a/src/koehsel.policy/koehsel/policy/profiles.zcml b/src/koehsel.policy/koehsel/policy/profiles.zcml
new file mode 100644 (file)
index 0000000..86474da
--- /dev/null
@@ -0,0 +1,22 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
+    i18n_domain="koehsel.theme">
+
+  <genericsetup:registerProfile
+      name="default"
+      title="Koehsel Site"
+      directory="profiles/default"
+      description='Extension profile for the Koehsel Site.'
+      provides="Products.GenericSetup.interfaces.EXTENSION"
+      />
+
+  <genericsetup:importStep
+      name="koehsel.policy.content"
+      title="Koehsel Site: initial site setup"
+      description="Create and customize initial site content."
+      handler=".setuphandlers.siteSetup">
+    <depends name="plone-content"/>
+  </genericsetup:importStep>
+
+</configure>
diff --git a/src/koehsel.policy/koehsel/policy/profiles/default/koehsel.policy_setup.txt b/src/koehsel.policy/koehsel/policy/profiles/default/koehsel.policy_setup.txt
new file mode 100644 (file)
index 0000000..3e135d9
--- /dev/null
@@ -0,0 +1 @@
+Marker file
index ade50ca..5273b2c 100644 (file)
@@ -2,7 +2,6 @@
 <metadata>
   <version>1</version>
   <dependencies>
-    <dependency>profile-easyshop.core:default</dependency>
     <dependency>profile-koehsel.theme:default</dependency>
   </dependencies>
 </metadata>
index 5140789..22b3a87 100644 (file)
@@ -1,11 +1,44 @@
-def setupVarious(context):
+from Products.CMFCore.utils import getToolByName
 
-    # Ordinarily, GenericSetup handlers check for the existence of XML files.
-    # Here, we are not parsing an XML file, but we use this text file as a
-    # flag to check that we actually meant for this import step to be run.
-    # The file is found in profiles/default.
+INSTALL_PRODUCTS = ['easyshop.core']
 
-    if context.readDataFile('koehsel.theme_various.txt') is None:
+def siteSetup(context):
+
+    if context.readDataFile('koehsel.policy_setup.txt') is None:
         return
 
-    # Add additional setup code here
+    site = context.getSite()
+
+    # Install EasyShop product
+
+    qi = getToolByName(site, 'portal_quickinstaller')
+    for p in INSTALL_PRODUCTS:
+        if not qi.isProductInstalled(p):
+            qi.installProduct(p)
+
+    # Add and publish shop instance
+
+    try: site.shop
+    except AttributeError:
+        site.invokeFactory(id='shop', type_name='EasyShop')
+        shop = site.shop
+        shop.title = 'Shop'
+        shop.shopOwner = 'admin'
+        wf = getToolByName(site, 'portal_workflow')    
+        if wf.getInfoFor(shop,'review_state','') != 'published':
+            wf.doActionFor(shop,'publish',comment='site setup')
+
+    # Hide Users, News and Events
+
+    for id in ('Members', 'news', 'events'):
+        ob = getattr(site,id)
+        if wf.getInfoFor(ob,'review_state','') != 'private':
+            wf.doActionFor(ob,'retract',comment='site setup')
+
+
+# Called via hackery in __init__.py
+def appInit(app):
+    try: app.site
+    except AttributeError:
+        app.manage_addProduct['CMFPlone'].addPloneSite(id='site',
+                                                       extension_ids=['koehsel.policy:default'])
diff --git a/src/koehsel.theme/koehsel.theme.egg-info/SOURCES.txt b/src/koehsel.theme/koehsel.theme.egg-info/SOURCES.txt
deleted file mode 100644 (file)
index 9e5a4e1..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-MANIFEST.in
-README.txt
-setup.cfg
-setup.py
-koehsel/__init__.py
-koehsel.theme.egg-info/PKG-INFO
-koehsel.theme.egg-info/SOURCES.txt
-koehsel.theme.egg-info/dependency_links.txt
-koehsel.theme.egg-info/entry_points.txt
-koehsel.theme.egg-info/namespace_packages.txt
-koehsel.theme.egg-info/not-zip-safe
-koehsel.theme.egg-info/paster_plugins.txt
-koehsel.theme.egg-info/requires.txt
-koehsel.theme.egg-info/top_level.txt
-koehsel/theme/__init__.py
-koehsel/theme/configure.zcml
-koehsel/theme/profiles.zcml
-koehsel/theme/setuphandlers.py
-koehsel/theme/skins.zcml
-koehsel/theme/tests.py
-koehsel/theme/version.txt
-koehsel/theme/browser/__init__.py
-koehsel/theme/browser/configure.zcml
-koehsel/theme/browser/interfaces.py
-koehsel/theme/browser/viewlet.pt
-koehsel/theme/browser/viewlets.py
-koehsel/theme/browser/images/README.txt
-koehsel/theme/browser/stylesheets/README.txt
-koehsel/theme/browser/stylesheets/main.css
-koehsel/theme/profiles/default/cssregistry.xml
-koehsel/theme/profiles/default/jsregistry.xml
-koehsel/theme/profiles/default/koehsel.theme_various.txt
-koehsel/theme/profiles/default/metadata.xml
-koehsel/theme/profiles/default/portlets.xml
-koehsel/theme/profiles/default/portlets.xml~
-koehsel/theme/profiles/default/skins.xml
-koehsel/theme/profiles/default/viewlets.xml
-koehsel/theme/skins/koehsel_theme_custom_images/CONTENT.txt
-koehsel/theme/skins/koehsel_theme_custom_images/logo.jpg
-koehsel/theme/skins/koehsel_theme_custom_templates/CONTENT.txt
-koehsel/theme/skins/koehsel_theme_styles/CONTENT.txt
-koehsel/theme/skins/koehsel_theme_styles/base_properties.props
\ No newline at end of file