[Checkins] SVN: five.localsitemanager/trunk/src/five/localsitemanager/ Fist passing at a working local site manager complete. Functional tests show

Rocky Burt rocky at serverzen.com
Thu Feb 22 16:15:18 EST 2007


Log message for revision 72768:
  Fist passing at a working local site manager complete.  Functional tests show
  nested sites working.
  

Changed:
  U   five.localsitemanager/trunk/src/five/localsitemanager/__init__.py
  U   five.localsitemanager/trunk/src/five/localsitemanager/browser.py
  A   five.localsitemanager/trunk/src/five/localsitemanager/browser.txt
  A   five.localsitemanager/trunk/src/five/localsitemanager/components.pt
  U   five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
  U   five.localsitemanager/trunk/src/five/localsitemanager/overrides.zcml
  U   five.localsitemanager/trunk/src/five/localsitemanager/tests.py

-=-
Modified: five.localsitemanager/trunk/src/five/localsitemanager/__init__.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/__init__.py	2007-02-22 20:18:25 UTC (rev 72767)
+++ five.localsitemanager/trunk/src/five/localsitemanager/__init__.py	2007-02-22 21:15:18 UTC (rev 72768)
@@ -1,10 +1,12 @@
-from Acquisition import aq_parent, aq_base
+from Acquisition import aq_parent, aq_inner
+from zope import interface
 from zope.component.globalregistry import base
 from zope.traversing.interfaces import IContainmentRoot
 from zope.app.component.interfaces import ISite
 from zope.component.persistentregistry import PersistentComponents
+from five.localsitemanager import interfaces
 from Products.Five.component.interfaces import IObjectManagerSite
-from Products.Five.component import enableSite
+from Products.Five.component import enableSite, disableSite
 
 def make_site(obj, iface=ISite):
     """Give the specified object required qualities to identify it as a proper
@@ -15,9 +17,18 @@
     if ISite.providedBy(obj):
         raise ValueError('This is already a site')
     
+    next = find_next_sitemanager(obj)
+    if next is None:
+        next = base
+
     enableSite(obj, iface=iface)
-    
-    components = PersistentComponents(name='five', bases=(base,))
+
+    name = 'five'
+    path = getattr(obj, 'getPhysicalPath', None)
+    if path is not None and callable(path):
+        name = '/'.join(path())
+
+    components = PersistentComponents(name=name, bases=(next,))
     obj.setSiteManager(components)
 
 def make_objectmanager_site(obj):
@@ -44,7 +55,7 @@
     if parent is not None:
         return parent
 
-    parent = aq_parent(obj)
+    parent = aq_parent(aq_inner(obj))
     if parent is not None:
         return parent
 
@@ -65,6 +76,8 @@
 
         try:
             container = get_parent(container)
+            if container is None:
+                return None
         except TypeError:
             # there was not enough context; probably run from a test
             return None

Modified: five.localsitemanager/trunk/src/five/localsitemanager/browser.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/browser.py	2007-02-22 20:18:25 UTC (rev 72767)
+++ five.localsitemanager/trunk/src/five/localsitemanager/browser.py	2007-02-22 21:15:18 UTC (rev 72768)
@@ -1,4 +1,7 @@
+from zope.component.globalregistry import base
 from five.localsitemanager import make_objectmanager_site
+from five.localsitemanager import interfaces
+
 from Products.Five.component.browser import ObjectManagerSiteView
 
 class ObjectManagerSiteView(ObjectManagerSiteView):
@@ -7,3 +10,20 @@
 
     def makeSite(self):
         make_objectmanager_site(self.context)
+
+    def sitemanagerTrail(self):
+        if not self.isSite():
+            return None
+
+        sm = self.context.getSiteManager()
+        trail = []
+        while sm is not None and sm != base:
+            trail.append(repr(sm))
+            sm = sm.__bases__[0]
+
+        if sm == base:
+            trail.append('Global Registry')
+
+        trail.reverse()
+
+        return ' => '.join(trail)

Added: five.localsitemanager/trunk/src/five/localsitemanager/browser.txt
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/browser.txt	2007-02-22 20:18:25 UTC (rev 72767)
+++ five.localsitemanager/trunk/src/five/localsitemanager/browser.txt	2007-02-22 21:15:18 UTC (rev 72768)
@@ -0,0 +1,79 @@
+Functional Tests
+================
+
+Set Up
+------
+
+Make this test available as a module so that stuff defined in here can
+be pickled properly:
+
+    >>> from zope.testing import module
+    >>> module.setUp(test, name='five.localsitemanager.browsertest')
+
+Load all of Five's configuration (this is a functional test):
+
+    >>> import Products.Five
+    >>> import five.localsitemanager
+    >>> from Products.Five.zcml import load_config, load_string
+    >>> load_config('configure.zcml', package=Products.Five)
+    >>> load_config('configure.zcml', package=five.localsitemanager)
+    >>> load_string('<includeOverrides package="five.localsitemanager" file="overrides.zcml" />')
+
+Enable local component lookup hooks:
+
+    >>> from zope.app.component.hooks import setHooks
+    >>> setHooks()
+
+User Set Up
+-----------
+
+    >>> uf = app.acl_users
+    >>> uf._doAddUser('admin', 'admin', ['Manager'], [])
+
+Create the test browser we'll be using:
+
+    >>> from Products.Five.testbrowser import Browser
+    >>> browser = Browser()
+    >>> browser.addHeader('Authorization', 'Basic admin:admin')
+
+Folder Set Up
+-------------
+
+Make a folder to use as a local site for component registration:
+
+    >>> browser.open('http://localhost/manage_addProduct/OFSP/folderAdd')
+    >>> browser.getControl(name='id').value = 'folder'
+    >>> browser.getControl('Add').click()
+    >>> browser.getLink('folder').click()
+
+Look up the ``components.html`` view and make sure the
+``Make Site`` action still works.
+
+    >>> browser.open('http://localhost/folder/components.html')
+    >>> browser.getControl('Make site').click()
+
+Make sure the site manager trail only leads back to the global component
+registry.
+
+    >>> '<dd class="sitemanager-trail">Global Registry =&gt; &lt;PersistentComponents /folder&gt;</dd>' in browser.contents
+    True
+
+Now we add a sub folder.
+
+    >>> browser.open('http://localhost/folder/manage_addProduct/OFSP/folderAdd')
+    >>> browser.getControl(name='id').value = 'subfolder'
+    >>> browser.getControl('Add').click()
+    >>> browser.getLink('folder').click()
+
+    >>> browser.open('http://localhost/folder/subfolder/components.html')
+    >>> browser.getControl('Make site').click()
+
+    >>> '<dd class="sitemanager-trail">Global Registry =&gt; &lt;PersistentComponents /folder&gt; =&gt; &lt;PersistentComponents /folder/subfolder&gt;</dd>' in browser.contents
+    True
+
+Clean up
+--------
+
+    >>> module.tearDown(test, name='five.localsitemanager.browsertest')
+    >>> from zope.testing.cleanup import cleanUp
+    >>> cleanUp()

Added: five.localsitemanager/trunk/src/five/localsitemanager/components.pt
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/components.pt	2007-02-22 20:18:25 UTC (rev 72767)
+++ five.localsitemanager/trunk/src/five/localsitemanager/components.pt	2007-02-22 21:15:18 UTC (rev 72768)
@@ -0,0 +1,31 @@
+<tal:tag condition="view/update"/>
+<html metal:use-macro="context/@@standard_macros/view"
+      i18n:domain="zope">
+  <body>
+  <div metal:fill-slot="body"
+       tal:define="sitemanagerTrail view/sitemanagerTrail">
+
+  <p i18n:translate="">Sites support local configuration of components.</p>
+
+  <dl tal:condition="sitemanagerTrail">
+    <dt>Site Manager Trail</dt>
+    <dd class="sitemanager-trail" tal:content="sitemanagerTrail">
+    </dd>
+  </dl>
+
+  <form action="." tal:attributes="action request/URL" method="post"
+        enctype="multipart/form-data">
+      <div class="row">
+        <div class="controls">
+          <input type="submit" value="Make site" name="MAKESITE"
+                 i18n:attributes="value" tal:condition="not:view/isSite" />
+          <input type="submit" value="Unmake site" name="UNMAKESITE" 
+                 i18n:attributes="value" tal:condition="view/isSite" />
+        </div>
+      </div>
+  </form>
+
+  </div>
+  </body>
+
+</html>

Modified: five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt	2007-02-22 20:18:25 UTC (rev 72767)
+++ five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt	2007-02-22 21:15:18 UTC (rev 72768)
@@ -16,7 +16,7 @@
     >>> make_objectmanager_site(site)
     >>> sitemanager = site.getSiteManager()
     >>> sitemanager
-    <PersistentComponents five>
+    <PersistentComponents ...>
 
 Make sure this site has it's ``__bases__`` configure appropriately.
 

Modified: five.localsitemanager/trunk/src/five/localsitemanager/overrides.zcml
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/overrides.zcml	2007-02-22 20:18:25 UTC (rev 72767)
+++ five.localsitemanager/trunk/src/five/localsitemanager/overrides.zcml	2007-02-22 21:15:18 UTC (rev 72768)
@@ -2,14 +2,12 @@
     xmlns="http://namespaces.zope.org/zope"
     xmlns:browser="http://namespaces.zope.org/browser">
 
-  <configure package="Products.Five.component">
-    <browser:page
-        for="OFS.interfaces.IObjectManager"
-        name="components.html"
-        class="five.localsitemanager.browser.ObjectManagerSiteView"
-        template="components.pt"
-        permission="five.ManageSite"
-        />
-  </configure>
+  <browser:page
+      for="OFS.interfaces.IObjectManager"
+      name="components.html"
+      class=".browser.ObjectManagerSiteView"
+      template="components.pt"
+      permission="five.ManageSite"
+      />
 
 </configure>

Modified: five.localsitemanager/trunk/src/five/localsitemanager/tests.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/tests.py	2007-02-22 20:18:25 UTC (rev 72767)
+++ five.localsitemanager/trunk/src/five/localsitemanager/tests.py	2007-02-22 21:15:18 UTC (rev 72768)
@@ -5,7 +5,9 @@
 def test_suite():
     return unittest.TestSuite([
         ZopeDocFileSuite('localsitemanager.txt',
-                         package="five.localsitemanager")
+                         package="five.localsitemanager"),
+        FunctionalDocFileSuite('browser.txt',
+                               package="five.localsitemanager")
         ])
 
 if __name__ == '__main__':



More information about the Checkins mailing list