[z3-checkins] r10365 - in z3/Five/trunk: . tests
tests/products/FiveTest
philikon at codespeak.net
philikon at codespeak.net
Wed Apr 6 15:24:16 MEST 2005
Author: philikon
Date: Wed Apr 6 15:24:16 2005
New Revision: 10365
Added:
z3/Five/trunk/sizeconfigure.py (contents, props changed)
z3/Five/trunk/tests/products/FiveTest/size.py (contents, props changed)
Modified:
z3/Five/trunk/CHANGES.txt
z3/Five/trunk/meta.zcml
z3/Five/trunk/tests/products/FiveTest/configure.zcml
z3/Five/trunk/tests/products/FiveTest/fancycontent.py
z3/Five/trunk/tests/test_five.py
Log:
Zope 3 style ``ISized`` adapters for objects are now exposed to the
ZMI and other Zope 2 frameworks via the known ``get_size`` method,
provided this is turned for the class in question via the
<five:sizable /> ZCML directive.
Modified: z3/Five/trunk/CHANGES.txt
==============================================================================
--- z3/Five/trunk/CHANGES.txt (original)
+++ z3/Five/trunk/CHANGES.txt Wed Apr 6 15:24:16 2005
@@ -1,12 +1,18 @@
Five Changes
============
+
+* Zope 3 style ``ISized`` adapters for objects are now exposed to the
+ ZMI and other Zope 2 frameworks via the known ``get_size`` method,
+ provided this is turned for the class in question via the
+ five:sizable ZCML directive.
+
* There is now a standard standard_macros. Five page templates can use
context/@@standard_macros/view to get the default site layout.
-* The addform and editform directive now supports the widget zcml subdirective,
-that previously was ignored.
+* The addform and editform directive now supports the widget ZCML
+ subdirective, that previously was ignored.
-* Five now supports the vocabulary zcml directive.
+* Five now supports the vocabulary ZCML directive.
Five 0.3 (2005-03-11)
---------------------
Modified: z3/Five/trunk/meta.zcml
==============================================================================
--- z3/Five/trunk/meta.zcml (original)
+++ z3/Five/trunk/meta.zcml Wed Apr 6 15:24:16 2005
@@ -259,6 +259,12 @@
/>
<meta:directive
+ name="sizable"
+ schema=".fivedirectives.ISendEventsDirective"
+ handler=".sizeconfigure.sizable"
+ />
+
+ <meta:directive
name="pagesFromDirectory"
schema=".fivedirectives.IPagesFromDirectoryDirective"
handler=".fiveconfigure.pagesFromDirectory"
Added: z3/Five/trunk/sizeconfigure.py
==============================================================================
--- (empty file)
+++ z3/Five/trunk/sizeconfigure.py Wed Apr 6 15:24:16 2005
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2004 Five Contributors. All rights reserved.
+#
+# This software is distributed under the terms of the Zope Public
+# License (ZPL) v2.1. See COPYING.txt for more information.
+#
+##############################################################################
+"""Use structured monkey-patching to enable ``ISized`` adapters for
+Zope 2 objects.
+
+$Id$
+"""
+from zope.app.size.interfaces import ISized
+from Products.Five.fiveconfigure import isFiveMethod
+
+def get_size(self):
+ size = ISized(self, None)
+ if size is not None:
+ unit, amount = size.sizeForSorting()
+ if unit == 'byte':
+ return amount
+ method = getattr(self, '__five_original_get_size', None)
+ if method is not None:
+ return self.__five_original_get_size()
+
+get_size.__five_method__ = True
+
+def classSizable(class_):
+ """Monkey the class to be sizable through Five"""
+ # tuck away the original method if necessary
+ if hasattr(class_, "get_size") and not isFiveMethod(class_.get_size):
+ class_.__five_original_get_size = class_.get_size
+ class_.get_size = get_size
+
+def sizable(_context, class_):
+ _context.action(
+ discriminator = ('five:sizable', class_),
+ callable = classSizable,
+ args=(class_,)
+ )
Modified: z3/Five/trunk/tests/products/FiveTest/configure.zcml
==============================================================================
--- z3/Five/trunk/tests/products/FiveTest/configure.zcml (original)
+++ z3/Five/trunk/tests/products/FiveTest/configure.zcml Wed Apr 6 15:24:16 2005
@@ -428,11 +428,32 @@
menu="testmenu"
/>
+ <!-- register size adapters -->
+
+ <five:sizable
+ class=".simplecontent.SimpleContent"
+ />
+
+ <five:sizable
+ class=".fancycontent.FancyContent"
+ />
+
+ <adapter
+ for=".interfaces.ISimpleContent"
+ provides="zope.app.size.interfaces.ISized"
+ factory=".size.SimpleContentSize"
+ />
+
+ <adapter
+ for=".interfaces.IFancyContent"
+ provides="zope.app.size.interfaces.ISized"
+ factory=".size.FancyContentSize"
+ />
<!-- subscribe to all events -->
<five:sendEvents
class=".simplecontent.SimpleContent"
- />
+ />
<subscriber
factory=".subscriber.objectEventSubscriber"
Modified: z3/Five/trunk/tests/products/FiveTest/fancycontent.py
==============================================================================
--- z3/Five/trunk/tests/products/FiveTest/fancycontent.py (original)
+++ z3/Five/trunk/tests/products/FiveTest/fancycontent.py Wed Apr 6 15:24:16 2005
@@ -23,7 +23,10 @@
class FancyContent(SimpleItem):
"""A class that already comes with its own __bobo_traverse__ handler.
- Quite fancy indeed."""
+ Quite fancy indeed.
+
+ It also comes with its own get_size method.
+ """
implements(IFancyContent)
meta_type = "Fancy Content"
@@ -32,6 +35,9 @@
def __bobo_traverse__(self, REQUEST, name):
return FancyAttribute(name).__of__(self)
+ def get_size(self):
+ return 43
+
InitializeClass(FancyContent)
def manage_addFancyContent(self, id, REQUEST=None):
Added: z3/Five/trunk/tests/products/FiveTest/size.py
==============================================================================
--- (empty file)
+++ z3/Five/trunk/tests/products/FiveTest/size.py Wed Apr 6 15:24:16 2005
@@ -0,0 +1,28 @@
+from zope.interface import implements
+from zope.app.size.interfaces import ISized
+
+class SimpleContentSize(object):
+ """Size for ``SimpleContent`` objects."""
+ implements(ISized)
+
+ def __init__(self, context):
+ self.context = context
+
+ def sizeForSorting(self):
+ return ('byte', 42)
+
+ def sizeForDisplay(self):
+ return "What is the meaning of life?"
+
+class FancyContentSize(object):
+ """Size for ``SimpleContent`` objects."""
+ implements(ISized)
+
+ def __init__(self, context):
+ self.context = context
+
+ def sizeForSorting(self):
+ return ('line', 143)
+
+ def sizeForDisplay(self):
+ return "That's not the meaning of life!"
Modified: z3/Five/trunk/tests/test_five.py
==============================================================================
--- z3/Five/trunk/tests/test_five.py (original)
+++ z3/Five/trunk/tests/test_five.py Wed Apr 6 15:24:16 2005
@@ -351,7 +351,6 @@
response = self.publish('/test_folder_1_/testoid/dirpage2')
self.assert_('page 2' in response.getBody())
-
class IRecurse(Interface):
pass
@@ -405,6 +404,17 @@
self.assertEquals('Test Menu Item 2', menu[1]['title'])
self.assertEquals('parakeet.html', menu[1]['action'])
+class SizeTest(FiveTestCase):
+
+ def test_no_get_size_on_original(self):
+ manage_addSimpleContent(self.folder, 'simple', 'Simple')
+ obj = self.folder.simple
+ self.assertEquals(obj.get_size(), 42)
+
+ def test_get_size_on_original_and_fallback(self):
+ manage_addFancyContent(self.folder, 'fancy', 'Fancy')
+ obj = self.folder.fancy
+ self.assertEquals(obj.get_size(), 43)
def test_suite():
from unittest import TestSuite, makeSuite
@@ -413,6 +423,7 @@
suite.addTest(makeSuite(FiveTest))
suite.addTest(makeSuite(PublishTest))
suite.addTest(makeSuite(MenuTest))
+ suite.addTest(makeSuite(SizeTest))
return suite
if __name__ == '__main__':
More information about the z3-checkins
mailing list