Skip to content

Commit

Permalink
- use the same constructor names and signatures as in zope.browserpage
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Jul 10, 2012
1 parent a4bd764 commit 37b326a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/Products/Five/browser/metaconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,13 @@ def page(_context, name, permission, for_=Interface,
cdict['__name__'] = name
if template:
# class and template
new_class = makeClassForTemplate(template, bases=(class_, ),
cdict=cdict, name=name)
new_class = SimpleViewClass(template, bases=(class_, ), name=name)
elif attribute != "__call__":
# we're supposed to make a page for an attribute (read:
# method) and it's not __call__. We thus need to create a
# new class using our mixin for attributes.
cdict.update({'__page_attribute__': attribute})
new_class = makeClass(class_.__name__,
(class_, ViewMixinForAttributes),
cdict)
new_class = makeClass(class_.__name__, (class_, simple), cdict)

# in case the attribute does not provide a docstring,
# ZPublisher refuses to publish it. So, as a workaround,
Expand All @@ -158,7 +155,7 @@ def page(_context, name, permission, for_=Interface,

else:
# template
new_class = makeClassForTemplate(template, name=name)
new_class = SimpleViewClass(template, name=name)

for n in ('', attribute):
required[n] = permission
Expand Down Expand Up @@ -428,8 +425,7 @@ def resourceDirectory(_context, name, directory, layer=IDefaultBrowserLayer,
)


class ViewMixinForAttributes(BrowserView,
zope.browserpage.metaconfigure.simple):
class simple(BrowserView, zope.browserpage.metaconfigure.simple):

# XXX: this alternative implementation would support permission checks for
# the attribute instead of the view
Expand Down Expand Up @@ -471,15 +467,19 @@ def __getitem__(self, name):
def __call__(self, *args, **kw):
return self.index(*args, **kw)

def makeClassForTemplate(filename, globals=None, used_for=None,
bases=(), cdict=None, name=u''):
# XXX needs to deal with security from the bases?
if cdict is None:

# Original version: zope.browserpage.simpleviewclass.SimpleViewClass
def SimpleViewClass(src, offering=None, used_for=None, bases=(), name=u''):
if bases:
cdict = getSecurityInfo(bases[0])
else:
cdict = {}
cdict.update({'index': ViewPageTemplateFile(filename, globals),
cdict.update({'index': ViewPageTemplateFile(src, offering),
'__name__': name})

bases += (ViewMixinForTemplates,)
class_ = makeClass("SimpleViewClass from %s" % filename, bases, cdict)

class_ = makeClass("SimpleViewClass from %s" % src, bases, cdict)

if used_for is not None:
class_.__used_for__ = used_for
Expand Down
4 changes: 2 additions & 2 deletions src/Products/Five/viewlet/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ represent the files in a table:
... </html>
... ''')

>>> from Products.Five.browser.metaconfigure import makeClassForTemplate
>>> Contents = makeClassForTemplate(contentsTemplate, name='contents.html')
>>> from Products.Five.browser.metaconfigure import SimpleViewClass
>>> Contents = SimpleViewClass(contentsTemplate, name='contents.html')


The Viewlet Manager
Expand Down

0 comments on commit 37b326a

Please sign in to comment.