[Checkins] SVN: z3ext.controlpanel/trunk/ - Fix configlet storage name

Nikolay Kim fafhrd at datacom.kz
Thu Aug 28 05:47:00 EDT 2008


Log message for revision 90537:
  - Fix configlet storage name
  - Added copier for data storage
  
  
  

Changed:
  U   z3ext.controlpanel/trunk/CHANGES.txt
  U   z3ext.controlpanel/trunk/setup.py
  U   z3ext.controlpanel/trunk/src/z3ext/controlpanel/README.txt
  U   z3ext.controlpanel/trunk/src/z3ext/controlpanel/browser/tests/README.txt
  U   z3ext.controlpanel/trunk/src/z3ext/controlpanel/configlet.py
  U   z3ext.controlpanel/trunk/src/z3ext/controlpanel/configure.zcml
  U   z3ext.controlpanel/trunk/src/z3ext/controlpanel/storage.py

-=-
Modified: z3ext.controlpanel/trunk/CHANGES.txt
===================================================================
--- z3ext.controlpanel/trunk/CHANGES.txt	2008-08-28 09:09:47 UTC (rev 90536)
+++ z3ext.controlpanel/trunk/CHANGES.txt	2008-08-28 09:46:57 UTC (rev 90537)
@@ -2,12 +2,16 @@
 CHANGES
 =======
 
-1.2.5 (2008-06-??)
+1.2.5 (2008-08-28)
 ------------------
 
 - Remove wrong html tag for category view
 
+- Fix configlet storage name
 
+- Added copier for data storage
+
+
 1.2.4 (2008-05-26)
 ------------------
 

Modified: z3ext.controlpanel/trunk/setup.py
===================================================================
--- z3ext.controlpanel/trunk/setup.py	2008-08-28 09:09:47 UTC (rev 90536)
+++ z3ext.controlpanel/trunk/setup.py	2008-08-28 09:46:57 UTC (rev 90537)
@@ -65,6 +65,7 @@
                           'zope.viewlet',
                           'zope.contentprovider',
                           'zope.cachedescriptors',
+			  'zope.lifecycleevent',
                           'zope.app.publisher',
                           'zope.app.component',
                           'zope.app.security',

Modified: z3ext.controlpanel/trunk/src/z3ext/controlpanel/README.txt
===================================================================
--- z3ext.controlpanel/trunk/src/z3ext/controlpanel/README.txt	2008-08-28 09:09:47 UTC (rev 90536)
+++ z3ext.controlpanel/trunk/src/z3ext/controlpanel/README.txt	2008-08-28 09:46:57 UTC (rev 90537)
@@ -36,7 +36,7 @@
   ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext"
   ...    i18n_domain="zope">
   ...   <z3ext:configlet
-  ...	    name="configlet1"
+  ...	   name="configlet1"
   ...      schema="z3ext.controlpanel.README.ITestConfiglet1"
   ...      title="Test configlet1"
   ...      description="Test configlet1 description" />

Modified: z3ext.controlpanel/trunk/src/z3ext/controlpanel/browser/tests/README.txt
===================================================================
--- z3ext.controlpanel/trunk/src/z3ext/controlpanel/browser/tests/README.txt	2008-08-28 09:09:47 UTC (rev 90536)
+++ z3ext.controlpanel/trunk/src/z3ext/controlpanel/browser/tests/README.txt	2008-08-28 09:46:57 UTC (rev 90537)
@@ -82,4 +82,3 @@
 
   >>> browser.getLink('Configlet1').click()
   >>> browser.getControl(name='form.buttons.save').click()
-  >>> browser.getControl(name='form.buttons.cancel').click()

Modified: z3ext.controlpanel/trunk/src/z3ext/controlpanel/configlet.py
===================================================================
--- z3ext.controlpanel/trunk/src/z3ext/controlpanel/configlet.py	2008-08-28 09:09:47 UTC (rev 90536)
+++ z3ext.controlpanel/trunk/src/z3ext/controlpanel/configlet.py	2008-08-28 09:46:57 UTC (rev 90537)
@@ -15,6 +15,7 @@
 
 $Id$
 """
+import traceback
 from zope import schema, interface
 from zope.location import Location
 from zope.component import getUtility, queryUtility
@@ -36,9 +37,17 @@
 
     @property
     def data(self):
-        data = getUtility(IDataStorage)
-        return removeSecurityProxy(data)[self.__name__]
+        storage = removeSecurityProxy(getUtility(IDataStorage))
 
+        if self.__id__ in storage:
+            return storage[self.__id__]
+
+        if self.__name__ in storage:
+            storage[self.__id__] = storage[self.__name__]
+            del storage[self.__name__]
+
+        return storage[self.__id__]
+
     def isAvailable(self):
         for test in self.__tests__:
             if not test(self):

Modified: z3ext.controlpanel/trunk/src/z3ext/controlpanel/configure.zcml
===================================================================
--- z3ext.controlpanel/trunk/src/z3ext/controlpanel/configure.zcml	2008-08-28 09:09:47 UTC (rev 90536)
+++ z3ext.controlpanel/trunk/src/z3ext/controlpanel/configure.zcml	2008-08-28 09:46:57 UTC (rev 90537)
@@ -23,6 +23,8 @@
   <!-- data storage -->
   <utility factory=".storage.DataStorage" />
 
+  <subscriber handler=".storage.dataStorageCopied" />
+
   <!-- default categories -->
   <z3ext:configlet
      name="system"

Modified: z3ext.controlpanel/trunk/src/z3ext/controlpanel/storage.py
===================================================================
--- z3ext.controlpanel/trunk/src/z3ext/controlpanel/storage.py	2008-08-28 09:09:47 UTC (rev 90536)
+++ z3ext.controlpanel/trunk/src/z3ext/controlpanel/storage.py	2008-08-28 09:46:57 UTC (rev 90537)
@@ -17,14 +17,21 @@
 """
 from BTrees.OOBTree import OOBTree
 
-from zope import interface
+from zope import interface, component, event
+from zope.proxy import removeAllProxies
+from zope.location.pickling import locationCopy
+from zope.location.interfaces import ILocation
 from zope.app.component.hooks import getSite
+from zope.app.component.interfaces import ISite
 from zope.annotation.interfaces import IAnnotations
+from zope.lifecycleevent import ObjectCopiedEvent
+from zope.lifecycleevent.interfaces import IObjectCopiedEvent
 from z3ext.controlpanel.interfaces import IDataStorage
 
-key = 'z3ext.controlpanel.Settings'
+ANNOTATION_KEY = 'z3ext.controlpanel.Settings'
 _temp = {}
 
+
 class DataStorage(object):
     interface.implements(IDataStorage)
 
@@ -35,10 +42,10 @@
         if ann is None:
             return _temp
 
-        storage = ann.get(key)
+        storage = ann.get(ANNOTATION_KEY)
         if storage is None:
             storage = OOBTree()
-            ann[key] = storage
+            ann[ANNOTATION_KEY] = storage
 
         return storage
 
@@ -50,3 +57,47 @@
             self._data[name] = data
 
         return data
+
+    def __setitem__(self, name, data):
+        self._data[name] = data
+
+    def __delitem__(self, name):
+        if name in self._data:
+            del self._data[name]
+
+    def __contains__(self, name):
+        return name in self._data
+
+
+ at component.adapter(ISite, IObjectCopiedEvent)
+def dataStorageCopied(site, event):
+    ann = IAnnotations(removeAllProxies(event.original), None)
+    if ann is None:
+        return
+
+    oldStorage = ann.get(ANNOTATION_KEY)
+    if oldStorage is None:
+        return
+
+    ann = IAnnotations(removeAllProxies(site), None)
+    if ann is None:
+        return
+
+    newStorage = ann.get(ANNOTATION_KEY)
+    if newStorage is None:
+        newStorage = OOBTree()
+        ann[key] = newStorage
+
+    for key, obj in oldStorage.items():
+        copy = locationCopy(obj)
+
+        if isinstance(obj, OOBTree):
+            for subkey, subobj in obj.items():
+                subcopy = locationCopy(subobj)
+                if ILocation.providedBy(obj):
+                    subcopy.__parent__ = subcopy.__name__ = None
+                    event.notify(ObjectCopiedEvent(subcopy, subobj))
+
+                copy[subkey] = subcopy
+
+        newStorage[key] = copy



More information about the Checkins mailing list