[z3-checkins] r5243 - z3/Five/trunk
philikon at codespeak.net
philikon at codespeak.net
Tue Jun 22 20:56:57 MEST 2004
Author: philikon
Date: Tue Jun 22 20:56:56 2004
New Revision: 5243
Modified:
z3/Five/trunk/fiveconfigure.py
Log:
When using attributes from a view class, use a special mixin class
that defined __browser_default__. This causes the ZPublisher to traverse
to the attribute directly, thus being able to inspect its parameters.
This again makes mapply work, thus fixing Guido's problem.
This is how Zope3 does it, too, btw.
Modified: z3/Five/trunk/fiveconfigure.py
==============================================================================
--- z3/Five/trunk/fiveconfigure.py (original)
+++ z3/Five/trunk/fiveconfigure.py Tue Jun 22 20:56:56 2004
@@ -17,6 +17,7 @@
from zope.configuration.exceptions import ConfigurationError
from zope.component.servicenames import Adapters, Presentation
from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from provideinterface import provideInterface
from viewable import Viewable
from api import BrowserView
@@ -77,11 +78,13 @@
new_class = SimpleViewClass(
template, bases=(class_, ),
cdict=cdict)
- else:
+ elif attribute != "__call__":
cdict.update({'__page_attribute__': attribute})
new_class = makeClass(class_.__name__,
- (class_, simple),
- cdict)
+ (class_, ViewMixinForAttributes),
+ cdict)
+ else:
+ new_class = class_
else:
# template
@@ -168,32 +171,24 @@
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=(), cdict=None):
- if offering is None:
- offering = sys._getframe(1).f_globals
+#
+# mixin classes / class factories
+#
+
+class ViewMixinForAttributes(BrowserView):
+
+ def __browser_default__(self, request):
+ if hasattr(self, 'index'):
+ attr = 'index'
+ else:
+ attr = self.__page_attribute__
+ return self, (attr,)
- #bases += (svc_simple, )
+def SimpleViewClass(src, template=None, used_for=None, bases=(), cdict=None):
# XXX needs to deal with security from the bases?
if cdict is None:
cdict = {}
- cdict.update({'index': ViewPageTemplateFile(src, offering)})
+ cdict.update({'index': ViewPageTemplateFile(src, template)})
class_ = makeClass("SimpleViewClass from %s" % src, bases, cdict)
if used_for is not None:
More information about the z3-checkins
mailing list