[z3-checkins] r5149 - in z3/Five/trunk: . tests
tests/products/FiveTest
faassen at codespeak.net
faassen at codespeak.net
Thu Jun 17 19:00:57 MEST 2004
Author: faassen
Date: Thu Jun 17 19:00:56 2004
New Revision: 5149
Added:
z3/Five/trunk/tests/products/FiveTest/falcon.pt
Modified:
z3/Five/trunk/browser.py
z3/Five/trunk/fiveconfigure.py
z3/Five/trunk/monkey.py
z3/Five/trunk/tests/products/FiveTest/configure.zcml
z3/Five/trunk/tests/test_five.py
z3/Five/trunk/viewable.py
Log:
* lots of hackery to make template views sort of work.
* refactored so finding attributes is more like Zope 3
Modified: z3/Five/trunk/browser.py
==============================================================================
--- z3/Five/trunk/browser.py (original)
+++ z3/Five/trunk/browser.py Thu Jun 17 19:00:56 2004
@@ -13,6 +13,8 @@
# as this makes Zope 2 traverse into that first!
def __call__(self, *args, **kw):
+ if hasattr(self, 'index'):
+ return self.index(self, *args, **kw)
attr = self.__page_attribute__
if attr == '__call__':
raise AttributeError("__call__")
Modified: z3/Five/trunk/fiveconfigure.py
==============================================================================
--- z3/Five/trunk/fiveconfigure.py (original)
+++ z3/Five/trunk/fiveconfigure.py Thu Jun 17 19:00:56 2004
@@ -8,8 +8,9 @@
from zope.component.servicenames import Adapters, Presentation
from zope.publisher.interfaces.browser import IBrowserRequest
from provideinterface import provideInterface
-from viewattribute import ViewAttribute
from viewable import Viewable
+from api import BrowserView
+from metaclass import makeClass
#def handler(serviceName, methodName, *args, **kwargs):
# method=getattr(getService(serviceName), methodName)
@@ -57,17 +58,10 @@
new_class = SimpleViewClass(
template, bases=(class_, ))
else:
- #if not hasattr(class_, 'browserDefault'):
- # cdict = {
- # 'browserDefault':
- # lambda self, request: (getattr(self, attribute), ())
- # }
- #else:
- # cdict = {}
-
- #cdict['__page_attribute__'] = attribute
- class_.__page_attribute__ = attribute
- new_class = class_
+ cdict = {'__page_attribute__': attribute }
+ new_class = makeClass(class_.__name__,
+ (class_, simple),
+ cdict)
else:
# template
@@ -141,3 +135,35 @@
callable = handler,
args = (Presentation, 'setDefaultSkin', name, _context.info)
)
+
+class simple(BrowserView):
+
+ def __call__(self, *a, **k):
+ # If a class doesn't provide it's own call, then get the attribute
+ # given by the browser default.
+
+ attr = self.__page_attribute__
+ if attr == '__call__':
+ raise AttributeError("__call__")
+
+ meth = getattr(self, attr)
+ return meth(*a, **k)
+
+import sys
+from zope.app.pagetemplate.simpleviewclass import simple as svc_simple
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+def SimpleViewClass(src, offering=None, used_for=None, bases=()):
+ if offering is None:
+ offering = sys._getframe(1).f_globals
+
+ #bases += (svc_simple, )
+
+ class_ = makeClass("SimpleViewClass from %s" % src, bases,
+ {'index': ViewPageTemplateFile(src, offering),
+ })
+
+ if used_for is not None:
+ class_.__used_for__ = used_for
+
+ return class_
Modified: z3/Five/trunk/monkey.py
==============================================================================
--- z3/Five/trunk/monkey.py (original)
+++ z3/Five/trunk/monkey.py Thu Jun 17 19:00:56 2004
@@ -17,3 +17,10 @@
HTTPRequest.getPresentationSkin = getPresentationSkin
HTTPRequest.setPresentationSkin = setPresentationSkin
+ HTTPRequest.debug = DebugFlags()
+
+class DebugFlags(object):
+ """Debugging flags."""
+
+ sourceAnnotations = False
+ showTAL = False
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 Thu Jun 17 19:00:56 2004
@@ -13,4 +13,11 @@
name="eagle.txt"
/>
+ <five:page
+ for=".interfaces.ISimpleContent"
+ class=".browser.SimpleContentView"
+ template="falcon.pt"
+ name="falcon.html"
+ />
+
</configure>
Added: z3/Five/trunk/tests/products/FiveTest/falcon.pt
==============================================================================
--- (empty file)
+++ z3/Five/trunk/tests/products/FiveTest/falcon.pt Thu Jun 17 19:00:56 2004
@@ -0,0 +1,2 @@
+<p>The falcon has taken flight</p>
+
Modified: z3/Five/trunk/tests/test_five.py
==============================================================================
--- z3/Five/trunk/tests/test_five.py (original)
+++ z3/Five/trunk/tests/test_five.py Thu Jun 17 19:00:56 2004
@@ -35,7 +35,7 @@
"Adapted: The method",
adapted.adaptedMethod())
- def test_view1(self):
+ def test_attribute_view(self):
self.root.manage_addProduct['FiveTest'].manage_addSimpleContent(
'testoid', 'Testoid')
test = self.root.test
@@ -44,6 +44,14 @@
data = view()
self.assertEquals('The eagle has landed', data)
+ def test_template_view(self):
+ self.root.manage_addProduct['FiveTest'].manage_addSimpleContent(
+ 'testoid', 'Testoid')
+ view = self.root.unrestrictedTraverse('testoid/falcon.html')
+ self.assert_(isinstance(view, SimpleContentView))
+ data = view()
+ self.assertEquals(u'<p>The falcon has taken flight</p>\n\n', data)
+
def test_view_backwards_compatibility(self):
self.root.manage_addProduct['FiveTest'].manage_addSimpleContent(
'testoid', 'Testoid')
Modified: z3/Five/trunk/viewable.py
==============================================================================
--- z3/Five/trunk/viewable.py (original)
+++ z3/Five/trunk/viewable.py Thu Jun 17 19:00:56 2004
@@ -2,9 +2,12 @@
from zope.component import getView, ComponentLookupError
from zope.interface import implements
from zope.publisher.interfaces.browser import IBrowserRequest
+from monkey import DebugFlags
class FakeRequest:
implements(IBrowserRequest)
+
+ debug = DebugFlags()
def getPresentationSkin(self):
return None
@@ -29,9 +32,9 @@
except (AttributeError, KeyError):
pass
# XXX not sure this is very useful
- method = REQUEST.get('REQUEST_METHOD', 'GET')
- if not method in ('GET', 'POST'):
- return NullResource(self, name, REQUEST).__of__(self)
+ #method = REQUEST.get('REQUEST_METHOD', 'GET')
+ #if not method in ('GET', 'POST'):
+ # return NullResource(self, name, REQUEST).__of__(self)
# Waaa. See Application.py
try:
More information about the z3-checkins
mailing list