[Checkins] SVN: z3ext.controlpanel/trunk/ Added helper class for creating content container configletders

Nikolay Kim fafhrd at datacom.kz
Wed Jan 28 05:02:21 EST 2009


Log message for revision 95285:
  Added helper class for creating content container configletders

Changed:
  U   z3ext.controlpanel/trunk/CHANGES.txt
  A   z3ext.controlpanel/trunk/src/z3ext/controlpanel/container.py

-=-
Modified: z3ext.controlpanel/trunk/CHANGES.txt
===================================================================
--- z3ext.controlpanel/trunk/CHANGES.txt	2009-01-28 09:40:51 UTC (rev 95284)
+++ z3ext.controlpanel/trunk/CHANGES.txt	2009-01-28 10:02:20 UTC (rev 95285)
@@ -3,6 +3,11 @@
 =======
 
 
+1.4.0 (Unreleased)
+------------------
+
+- Added helper class for creating content container configlet
+
 - Added browser:containerViews for data storage
 
 - Styles updated

Added: z3ext.controlpanel/trunk/src/z3ext/controlpanel/container.py
===================================================================
--- z3ext.controlpanel/trunk/src/z3ext/controlpanel/container.py	                        (rev 0)
+++ z3ext.controlpanel/trunk/src/z3ext/controlpanel/container.py	2009-01-28 10:02:20 UTC (rev 95285)
@@ -0,0 +1,97 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Use configlet as content container
+
+$Id:  2007-12-12 12:27:02Z fafhrd $
+"""
+from zope import interface, component
+from zope.proxy import removeAllProxies
+from zope.proxy import ProxyBase, getProxiedObject, non_overridable
+from zope.proxy.decorator import DecoratorSpecificationDescriptor
+from zope.security.decorator import DecoratedSecurityCheckerDescriptor
+from zope.location.interfaces import ILocation
+from zope.location.location import ClassAndInstanceDescr
+from zope.app.container.contained import uncontained
+
+from z3ext.content.type.order import Reordable
+from z3ext.content.type.interfaces import IOrder
+from z3ext.content.type.container import ContentContainer
+from z3ext.controlpanel.configlet import Configlet
+
+
+class ContentContainerConfiglet(ContentContainer, Configlet):
+
+    def __init__(self, tests=()):
+        Configlet.__init__(self, tests)
+
+    @property
+    def _SampleContainer__data(self):
+        return self.data
+
+    def get(self, key, default=None):
+        item = super(ContentContainerConfiglet, self).get(key, default)
+
+        if item is default:
+            return item
+
+        return ItemLocationProxy(removeAllProxies(item), self)
+
+    def __iter__(self):
+        return iter(self.data)
+
+    def __getitem__(self, key):
+        item = super(ContentContainerConfiglet, self).__getitem__(key)
+
+        return ItemLocationProxy(removeAllProxies(item), self)
+
+    def __delitem__(self, key):
+        uncontained(self[key], self, key)
+        del self.data[key]
+
+
+class ConfigletContainerOrder(Reordable):
+    @component.adapter(ContentContainerConfiglet)
+
+    def __init__(self, context):
+        context = removeAllProxies(context)
+        super(ConfigletContainerOrder, self).__init__(context.data)
+
+        self.context = context
+
+
+class ItemLocationProxy(ProxyBase):
+    interface.implements(ILocation)
+
+    __slots__ = '__parent__'
+    __safe_for_unpickling__ = True
+
+    def __new__(self, ob, container=None):
+        return ProxyBase.__new__(self, ob)
+
+    def __init__(self, ob, container=None):
+        ProxyBase.__init__(self, ob)
+        self.__parent__ = container
+
+    @non_overridable
+    def __reduce__(self, proto=None):
+        raise TypeError("Not picklable")
+
+    __doc__ = ClassAndInstanceDescr(
+        lambda inst: getProxiedObject(inst).__doc__,
+        lambda cls, __doc__ = __doc__: __doc__,
+        )
+
+    __reduce_ex__ = __reduce__
+    __providedBy__ = DecoratorSpecificationDescriptor()
+    __Security_checker__ = DecoratedSecurityCheckerDescriptor()



More information about the Checkins mailing list