Commit 37b326ab authored by 's avatar

- use the same constructor names and signatures as in zope.browserpage

parent a4bd7649
...@@ -125,16 +125,13 @@ def page(_context, name, permission, for_=Interface, ...@@ -125,16 +125,13 @@ def page(_context, name, permission, for_=Interface,
cdict['__name__'] = name cdict['__name__'] = name
if template: if template:
# class and template # class and template
new_class = makeClassForTemplate(template, bases=(class_, ), new_class = SimpleViewClass(template, bases=(class_, ), name=name)
cdict=cdict, name=name)
elif attribute != "__call__": elif attribute != "__call__":
# we're supposed to make a page for an attribute (read: # we're supposed to make a page for an attribute (read:
# method) and it's not __call__. We thus need to create a # method) and it's not __call__. We thus need to create a
# new class using our mixin for attributes. # new class using our mixin for attributes.
cdict.update({'__page_attribute__': attribute}) cdict.update({'__page_attribute__': attribute})
new_class = makeClass(class_.__name__, new_class = makeClass(class_.__name__, (class_, simple), cdict)
(class_, ViewMixinForAttributes),
cdict)
# in case the attribute does not provide a docstring, # in case the attribute does not provide a docstring,
# ZPublisher refuses to publish it. So, as a workaround, # ZPublisher refuses to publish it. So, as a workaround,
...@@ -158,7 +155,7 @@ def page(_context, name, permission, for_=Interface, ...@@ -158,7 +155,7 @@ def page(_context, name, permission, for_=Interface,
else: else:
# template # template
new_class = makeClassForTemplate(template, name=name) new_class = SimpleViewClass(template, name=name)
for n in ('', attribute): for n in ('', attribute):
required[n] = permission required[n] = permission
...@@ -428,8 +425,7 @@ def resourceDirectory(_context, name, directory, layer=IDefaultBrowserLayer, ...@@ -428,8 +425,7 @@ def resourceDirectory(_context, name, directory, layer=IDefaultBrowserLayer,
) )
class ViewMixinForAttributes(BrowserView, class simple(BrowserView, zope.browserpage.metaconfigure.simple):
zope.browserpage.metaconfigure.simple):
# XXX: this alternative implementation would support permission checks for # XXX: this alternative implementation would support permission checks for
# the attribute instead of the view # the attribute instead of the view
...@@ -471,15 +467,19 @@ class ViewMixinForTemplates(BrowserView): ...@@ -471,15 +467,19 @@ class ViewMixinForTemplates(BrowserView):
def __call__(self, *args, **kw): def __call__(self, *args, **kw):
return self.index(*args, **kw) return self.index(*args, **kw)
def makeClassForTemplate(filename, globals=None, used_for=None,
bases=(), cdict=None, name=u''): # Original version: zope.browserpage.simpleviewclass.SimpleViewClass
# XXX needs to deal with security from the bases? def SimpleViewClass(src, offering=None, used_for=None, bases=(), name=u''):
if cdict is None: if bases:
cdict = getSecurityInfo(bases[0])
else:
cdict = {} cdict = {}
cdict.update({'index': ViewPageTemplateFile(filename, globals), cdict.update({'index': ViewPageTemplateFile(src, offering),
'__name__': name}) '__name__': name})
bases += (ViewMixinForTemplates,) bases += (ViewMixinForTemplates,)
class_ = makeClass("SimpleViewClass from %s" % filename, bases, cdict)
class_ = makeClass("SimpleViewClass from %s" % src, bases, cdict)
if used_for is not None: if used_for is not None:
class_.__used_for__ = used_for class_.__used_for__ = used_for
......
...@@ -484,8 +484,8 @@ represent the files in a table: ...@@ -484,8 +484,8 @@ represent the files in a table:
... </html> ... </html>
... ''') ... ''')
>>> from Products.Five.browser.metaconfigure import makeClassForTemplate >>> from Products.Five.browser.metaconfigure import SimpleViewClass
>>> Contents = makeClassForTemplate(contentsTemplate, name='contents.html') >>> Contents = SimpleViewClass(contentsTemplate, name='contents.html')
The Viewlet Manager The Viewlet Manager
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment