Skip to content

Commit

Permalink
Cut startup time in half :)
Browse files Browse the repository at this point in the history
Merged revisions 25249 - 25251 from trunk
  • Loading branch information
Jim Fulton committed Jun 4, 2004
0 parents commit 9e78aa5
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 0 deletions.
75 changes: 75 additions & 0 deletions browser/metaconfigure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id$
"""

from zope.interface import Interface
from zope.configuration.fields import GlobalObject
from zope.schema import Id
from zope.app.publisher.browser.viewmeta import page, view
from zope.app.container.browser.contents import Contents
from zope.app.container.browser.adding import Adding
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.security.fields import Permission

class IContainerViews(Interface):
"""Define a container views"""

for_ = GlobalObject(
title=u"The interface this containerViews are for.",
description=u"""
The containerViews will be for all objects that implement this
interface.""",
required=True
)

contents = Permission(
title=u"The permission needed for content page.",
required=False,
)

index = Permission(
title=u"The permission needed for index page.",
required=False,
)

add = Permission(
title=u"The permission needed for add page.",
required=False,
)


def containerViews(_context, for_, contents=None, add=None, index=None):
"""Create an container view for a given content type"""

if for_ is None:
raise ValueError("A for interface must be specified.")

if contents is not None:
page(_context, name='contents.html', permission=contents,
for_=for_, class_=Contents, attribute='contents',
menu='zmi_views', title=_('Contents'))

if index is not None:
page(_context, name='index.html', permission=index, for_=for_,
class_=Contents, attribute='contents')

if add is not None:
viewObj = view(_context, name='+', menu='zmi_actions',
title=_('Add'), for_=for_, permission=add,
class_=Adding)
viewObj.page(_context, name='index.html', attribute='index')
viewObj.page(_context, name='action.html', attribute='action')
viewObj()
148 changes: 148 additions & 0 deletions browser/tests/test_directive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""'containerView' directive test
$Id$
"""
import re
import pprint
import cStringIO

import unittest
from zope.interface import Interface
from zope.testing.doctestunit import DocTestSuite
from zope.app.container.browser.metaconfigure import containerViews

atre = re.compile(' at [0-9a-fA-Fx]+')

class Context:
actions = ()

def action(self, discriminator, callable, args):
self.actions += ((discriminator, callable, args), )
self.info = 'info'

def __repr__(self):
stream = cStringIO.StringIO()
pprinter = pprint.PrettyPrinter(stream=stream, width=60)
pprinter.pprint(self.actions)
r = stream.getvalue()
return (''.join(atre.split(r))).strip()

class I(Interface):
pass

def test_containerViews():
"""
>>> context = Context()
>>> containerViews(context, for_=I, contents='zope.ManageContent',
... add='zope.ManageContent', index='zope.View')
>>> context
((('browser:menuItem',
'zmi_views',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
u'Contents'),
<bound method GlobalBrowserMenuService.menuItem of <zope.app.publisher.browser.globalbrowsermenuservice.GlobalBrowserMenuService object>>,
('zmi_views',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
'@@contents.html',
u'Contents',
'',
None,
'zope.ManageContent',
None)),
(None,
<function provideInterface>,
('',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>)),
(('view',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
'contents.html',
<InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
'default'),
<function handler>,
('Presentation',
'provideAdapter',
<InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
<class 'zope.app.publisher.browser.viewmeta.Contents'>,
'contents.html',
[<InterfaceClass zope.app.container.browser.tests.test_directive.I>],
<InterfaceClass zope.interface.Interface>,
'default',
'info')),
(None,
<function provideInterface>,
('',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>)),
(('view',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
'index.html',
<InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
'default'),
<function handler>,
('Presentation',
'provideAdapter',
<InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
<class 'zope.app.publisher.browser.viewmeta.Contents'>,
'index.html',
[<InterfaceClass zope.app.container.browser.tests.test_directive.I>],
<InterfaceClass zope.interface.Interface>,
'default',
'info')),
(('browser:menuItem',
'zmi_actions',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
u'Add'),
<bound method GlobalBrowserMenuService.menuItem of <zope.app.publisher.browser.globalbrowsermenuservice.GlobalBrowserMenuService object>>,
('zmi_actions',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
'@@+',
u'Add',
'',
None,
'zope.ManageContent',
None)),
(None,
<function provideInterface>,
('',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>)),
(None,
<function provideInterface>,
('', <InterfaceClass zope.interface.Interface>)),
(('view',
<InterfaceClass zope.app.container.browser.tests.test_directive.I>,
'+',
<InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
'default',
<InterfaceClass zope.interface.Interface>),
<function handler>,
('Presentation',
'provideAdapter',
<InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
<class 'zope.app.publisher.browser.viewmeta.+'>,
'+',
[<InterfaceClass zope.app.container.browser.tests.test_directive.I>],
<InterfaceClass zope.interface.Interface>,
'default',
'info')))
"""


def test_suite():
return unittest.TestSuite((
DocTestSuite(),
))

if __name__ == '__main__':
unittest.main()

0 comments on commit 9e78aa5

Please sign in to comment.