[z3-checkins] r5844 - in z3/Five/branch/dc-experiments: . tests
tests/products/FiveTest
dreamcatcher at codespeak.net
dreamcatcher at codespeak.net
Mon Aug 2 18:23:13 MEST 2004
Author: dreamcatcher
Date: Mon Aug 2 18:23:12 2004
New Revision: 5844
Modified:
z3/Five/branch/dc-experiments/browserconfigure.py
z3/Five/branch/dc-experiments/configure.zcml
z3/Five/branch/dc-experiments/fiveconfigure.py
z3/Five/branch/dc-experiments/meta.zcml
z3/Five/branch/dc-experiments/tests/products/FiveTest/__init__.py
z3/Five/branch/dc-experiments/tests/products/FiveTest/configure.zcml
z3/Five/branch/dc-experiments/tests/products/FiveTest/interfaces.py
z3/Five/branch/dc-experiments/tests/products/FiveTest/simplecontent.py
z3/Five/branch/dc-experiments/tests/test_five.py
Log:
five:viewable is back, now really meaning it. implemented browser:defaultView
Modified: z3/Five/branch/dc-experiments/browserconfigure.py
==============================================================================
--- z3/Five/branch/dc-experiments/browserconfigure.py (original)
+++ z3/Five/branch/dc-experiments/browserconfigure.py Mon Aug 2 18:23:12 2004
@@ -147,6 +147,19 @@
menu=menu, title=title,
**(self.opts))
+def defaultView(_context, name, for_=None):
+
+ type = IBrowserRequest
+
+ _context.action(
+ discriminator = ('defaultViewName', for_, type, name),
+ callable = handler,
+ args = (Presentation,
+ 'setDefaultViewName', for_, type, name),
+ )
+
+ _handle_for(_context, for_)
+
def _handle_for(_context, for_):
if for_ is not None:
_context.action(
Modified: z3/Five/branch/dc-experiments/configure.zcml
==============================================================================
--- z3/Five/branch/dc-experiments/configure.zcml (original)
+++ z3/Five/branch/dc-experiments/configure.zcml Mon Aug 2 18:23:12 2004
@@ -41,6 +41,7 @@
<!-- make Zope 2's REQUEST implement the right thing -->
<five:implements class="ZPublisher.HTTPRequest.HTTPRequest"
- interface="zope.publisher.interfaces.browser.IBrowserRequest" />
+ interface="zope.publisher.interfaces.browser.IBrowserRequest"
+ />
</configure>
Modified: z3/Five/branch/dc-experiments/fiveconfigure.py
==============================================================================
--- z3/Five/branch/dc-experiments/fiveconfigure.py (original)
+++ z3/Five/branch/dc-experiments/fiveconfigure.py Mon Aug 2 18:23:12 2004
@@ -18,7 +18,7 @@
from zope.interface import classImplements
from zope.configuration import xmlconfig
from zope.app.component.interface import provideInterface
-
+from viewable import Viewable
from traversable import Traversable
def findProducts():
@@ -68,6 +68,12 @@
def classTraversable(class_):
# If a class already has this attribute, it means it is either a
+ # subclass of api.Viewable or was already processed with this
+ # directive; in either case, do nothing... except in the case were
+ # the class overrides the attribute instead of getting it from
+ # a base class. In this case, we suppose that the class probably
+ # didn't bother with the base classes attribute anyway.
+ # If a class already has this attribute, it means it is either a
# subclass of api.Traversable or was already processed with this
# directive; in either case, do nothing... except in the case were
# the class overrides __bobo_traverse__ instead of getting it from
@@ -93,15 +99,72 @@
def traversable(_context, class_):
_context.action(
- discriminator = (class_,),
+ discriminator = ('five:traversable', class_,),
callable = classTraversable,
args = (class_,)
)
def viewable(_context, class_):
dotted_name = "...%s" % class_.__name__
- warnings.warn('<five:viewable class="%(k)s" /> is deprecated. '
- 'Please switch to <five:traversable class="%(k)s" />' %
+ warnings.warn('<five:viewable class="%(k)s" /> has changed meaning. '
+ 'Please switch to <five:traversable class="%(k)s" />'
+ 'unless you know what you are doing.' %
{'k':dotted_name},
DeprecationWarning)
- traversable(_context, class_)
+ _context.action(
+ discriminator = ('five:viewable', class_,),
+ callable = classViewable,
+ args = (class_,)
+ )
+
+def classViewable(class_):
+ # If a class already has this attribute, it means it is either a
+ # subclass of api.Viewable or was already processed with this
+ # directive; in either case, do nothing... except in the case were
+ # the class overrides the attribute instead of getting it from
+ # a base class. In this case, we suppose that the class probably
+ # didn't bother with the base classes attribute anyway.
+ if (hasattr(class_, '__five_viewable__') and
+ hasattr(class_, '__dict__') and
+ (not class_.__dict__.has_key('__browser_default__') and
+ not class_.__dict__.has_key('__call__') and
+ not class_.__dict__.has_key('index_html'))):
+ return
+
+ if not hasattr(class_, '__dict__'):
+ # XXX Should raise an error maybe?
+ return
+
+ if class_.__dict__.has_key('__browser_default__'):
+ # if there's an existing __browser_default__ hook already, use that
+ # as the fallback
+ setattr(class_, "__fallback_default__",
+ class_.__browser_default__)
+ else:
+ setattr(class_, "__fallback_default__",
+ Viewable.__fallback_default__)
+
+ if class_.__dict__.has_key('index_html'):
+ # if there's an existing index_html already, use that
+ # as the fallback
+ setattr(class_, "fallback_index_html__",
+ class_.index_html)
+ else:
+ setattr(class_, "fallback_index_html__",
+ Viewable.fallback_index_html__)
+
+ if class_.__dict__.has_key('__call__'):
+ # if there's an existing __call__ already, use that
+ # as the fallback
+ setattr(class_, "fallback_call__",
+ class_.__call__)
+ else:
+ setattr(class_, "fallback_call__",
+ Viewable.fallback_call__)
+
+
+ setattr(class_, '__browser_default__', Viewable.__browser_default__)
+ setattr(class_, '__call__', Viewable.__call__)
+ setattr(class_, 'index_html', Viewable.index_html)
+ setattr(class_, '__five_viewable__', True)
+
Modified: z3/Five/branch/dc-experiments/meta.zcml
==============================================================================
--- z3/Five/branch/dc-experiments/meta.zcml (original)
+++ z3/Five/branch/dc-experiments/meta.zcml Mon Aug 2 18:23:12 2004
@@ -98,6 +98,12 @@
/>
<meta:directive
+ name="defaultView"
+ schema="zope.app.publisher.browser.metadirectives.IDefaultViewDirective"
+ handler=".browserconfigure.defaultView"
+ />
+
+ <meta:directive
name="page"
schema="zope.app.publisher.browser.metadirectives.IPageDirective"
handler=".browserconfigure.page"
Modified: z3/Five/branch/dc-experiments/tests/products/FiveTest/__init__.py
==============================================================================
--- z3/Five/branch/dc-experiments/tests/products/FiveTest/__init__.py (original)
+++ z3/Five/branch/dc-experiments/tests/products/FiveTest/__init__.py Mon Aug 2 18:23:12 2004
@@ -11,6 +11,18 @@
)
context.registerClass(
+ simplecontent.CallableSimpleContent,
+ constructors = (simplecontent.manage_addSimpleContentForm,
+ simplecontent.manage_addCallableSimpleContent),
+ )
+
+ context.registerClass(
+ simplecontent.IndexSimpleContent,
+ constructors = (simplecontent.manage_addSimpleContentForm,
+ simplecontent.manage_addIndexSimpleContent),
+ )
+
+ context.registerClass(
fancycontent.FancyContent,
constructors = (fancycontent.manage_addFancyContent,)
)
Modified: z3/Five/branch/dc-experiments/tests/products/FiveTest/configure.zcml
==============================================================================
--- z3/Five/branch/dc-experiments/tests/products/FiveTest/configure.zcml (original)
+++ z3/Five/branch/dc-experiments/tests/products/FiveTest/configure.zcml Mon Aug 2 18:23:12 2004
@@ -2,19 +2,49 @@
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five">
- <!-- this is a test whether five:viewable can be called more than
+ <!-- this is a test whether five:traversable can be called more than
once on a class; SimpleContent inherits from api.Viewable, so
one directive suffices here -->
<five:traversable class=".simplecontent.SimpleContent" />
+ <five:viewable class=".simplecontent.SimpleContent" />
- <!-- this tests whether five:viewable can be called on a class that
+ <browser:defaultView
+ for=".interfaces.ISimpleContent"
+ name="eagle.txt"
+ />
+
+ <!-- this tests whether five:traversable can be called on a class that
already provides __bobo_traverse__, such as our FancyContent -->
<five:traversable class=".fancycontent.FancyContent" />
+ <!-- this tests whether five:viewable can be called on a class that
+ already provides __call__, such as our
+ CallableSimpleContent
+ -->
+
+ <five:viewable class=".simplecontent.CallableSimpleContent" />
+
+ <browser:defaultView
+ for=".interfaces.ICallableSimpleContent"
+ name="__call__"
+ />
+
+ <!-- this tests whether five:viewable can be called on a class that
+ already provides index_html, such as our
+ IndexSimpleContent
+ -->
+
+ <five:viewable class=".simplecontent.IndexSimpleContent" />
+
+ <browser:defaultView
+ for=".interfaces.IIndexSimpleContent"
+ name="index_html"
+ />
+
<adapter
for=".interfaces.IAdaptable"
provides=".interfaces.IAdapted"
Modified: z3/Five/branch/dc-experiments/tests/products/FiveTest/interfaces.py
==============================================================================
--- z3/Five/branch/dc-experiments/tests/products/FiveTest/interfaces.py (original)
+++ z3/Five/branch/dc-experiments/tests/products/FiveTest/interfaces.py Mon Aug 2 18:23:12 2004
@@ -27,5 +27,11 @@
class ISimpleContent(Interface):
pass
+class ICallableSimpleContent(ISimpleContent):
+ pass
+
+class IIndexSimpleContent(ISimpleContent):
+ pass
+
class IFancyContent(Interface):
pass
Modified: z3/Five/branch/dc-experiments/tests/products/FiveTest/simplecontent.py
==============================================================================
--- z3/Five/branch/dc-experiments/tests/products/FiveTest/simplecontent.py (original)
+++ z3/Five/branch/dc-experiments/tests/products/FiveTest/simplecontent.py Mon Aug 2 18:23:12 2004
@@ -5,7 +5,7 @@
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.Five.api import Traversable
from zope.interface import implements
-from interfaces import ISimpleContent
+from interfaces import ISimpleContent, ICallableSimpleContent, IIndexSimpleContent
class SimpleContent(SimpleItem, Traversable):
implements(ISimpleContent)
@@ -29,6 +29,23 @@
InitializeClass(SimpleContent)
+class CallableSimpleContent(SimpleItem):
+ """A Viewable piece of content"""
+ implements(ICallableSimpleContent)
+
+ def __call__(self, *args, **kw):
+ """ """
+ return "Default __call__ called"
+
+class IndexSimpleContent(SimpleItem):
+ """A Viewable piece of content"""
+ implements(IIndexSimpleContent)
+
+ def index_html(self, *args, **kw):
+ """ """
+ return "Default index_html called"
+
+
manage_addSimpleContentForm = PageTemplateFile(
"www/simpleContentAdd", globals(),
__name__ = 'manage_addSimpleContentForm')
@@ -38,3 +55,15 @@
id = self._setObject(id, SimpleContent(id, title))
add_and_edit(self, id, REQUEST)
return ''
+
+def manage_addCallableSimpleContent(self, id, title, REQUEST=None):
+ """Add the viewable simple content."""
+ id = self._setObject(id, CallableSimpleContent(id, title))
+ add_and_edit(self, id, REQUEST)
+ return ''
+
+def manage_addIndexSimpleContent(self, id, title, REQUEST=None):
+ """Add the viewable simple content."""
+ id = self._setObject(id, IndexSimpleContent(id, title))
+ add_and_edit(self, id, REQUEST)
+ return ''
Modified: z3/Five/branch/dc-experiments/tests/test_five.py
==============================================================================
--- z3/Five/branch/dc-experiments/tests/test_five.py (original)
+++ z3/Five/branch/dc-experiments/tests/test_five.py Mon Aug 2 18:23:12 2004
@@ -40,6 +40,10 @@
def afterSetUp(self):
self.folder.manage_addProduct['FiveTest'].manage_addSimpleContent(
'testoid', 'Testoid')
+ self.folder.manage_addProduct['FiveTest'].manage_addCallableSimpleContent(
+ 'testcall', 'TestCall')
+ self.folder.manage_addProduct['FiveTest'].manage_addIndexSimpleContent(
+ 'testindex', 'TestIndex')
uf = self.folder.acl_users
uf._doAddUser('manager', 'r00t', ['Manager'], [])
self.login('manager')
@@ -217,12 +221,25 @@
view = self.folder.unrestrictedTraverse(base % macro)
self.failUnless(view)
+ def test_existing_call(self):
+ view = self.folder.unrestrictedTraverse('testcall')
+ self.assertEquals("Default __call__ called", view())
+
+ def test_existing_index(self):
+ view = self.folder.unrestrictedTraverse('testindex')
+ self.assertEquals("Default index_html called", view())
+
+
class PublishTestCase(Functional, ZopeTestCase.ZopeTestCase):
"""Test a few publishing features"""
def afterSetUp(self):
self.folder.manage_addProduct['FiveTest'].manage_addSimpleContent(
'testoid', 'Testoid')
+ self.folder.manage_addProduct['FiveTest'].manage_addCallableSimpleContent(
+ 'testcall', 'TestCall')
+ self.folder.manage_addProduct['FiveTest'].manage_addIndexSimpleContent(
+ 'testindex', 'TestIndex')
uf = self.folder.acl_users
uf._doAddUser('viewer', 'secret', [], [])
uf._doAddUser('manager', 'r00t', ['Manager'], [])
@@ -258,6 +275,18 @@
response = self.publish(url, basic='manager:r00t')
self.assertEquals(200, response.getStatus())
+ def test_existing_call(self):
+ response = self.publish('/test_folder_1_/testcall')
+ self.assertEquals("Default __call__ called", response.getBody())
+
+ def test_existing_index(self):
+ response = self.publish('/test_folder_1_/testindex')
+ self.assertEquals("Default index_html called", response.getBody())
+
+ def test_default_view(self):
+ response = self.publish('/test_folder_1_/testoid', basic='manager:r00t')
+ self.assertEquals("The eagle has landed", response.getBody())
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(FiveTestCase))
More information about the z3-checkins
mailing list