[Zope3-checkins] SVN: Zope3/trunk/ Implemented issue 292.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Feb 27 18:28:09 EST 2005
Log message for revision 29328:
Implemented issue 292.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/doc/TODO.txt
U Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
U Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-02-27 23:12:30 UTC (rev 29327)
+++ Zope3/trunk/doc/CHANGES.txt 2005-02-27 23:28:09 UTC (rev 29328)
@@ -10,6 +10,8 @@
New features
+ - Implemented issue 292: Add factory to browser:resource directive
+
- Implemented issue 309: <schemadisplay> should support <widget>
- Developed a generic browser:form directive. It is pretty much the same
Modified: Zope3/trunk/doc/TODO.txt
===================================================================
--- Zope3/trunk/doc/TODO.txt 2005-02-27 23:12:30 UTC (rev 29327)
+++ Zope3/trunk/doc/TODO.txt 2005-02-27 23:28:09 UTC (rev 29328)
@@ -11,8 +11,6 @@
- Support for iterable sources
-- Issue 292: Add factory to browser:resource directive
-
- Issue 295: Sort out defaultView
- Allow adapters (including views) to be registered for classes
Modified: Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2005-02-27 23:12:30 UTC (rev 29327)
+++ Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py 2005-02-27 23:28:09 UTC (rev 29328)
@@ -253,6 +253,14 @@
required=True
)
+ factory = GlobalObject(
+ title=u"Resource Factory",
+ description=u"The factory used to create the resource. The factory "
+ u"should only expect to get the request passed when "
+ u"called.",
+ required=False
+ )
+
file = Path(
title=u"File",
description=u"The file containing the resource data.",
Modified: Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py 2005-02-27 23:12:30 UTC (rev 29327)
+++ Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py 2005-02-27 23:28:09 UTC (rev 29328)
@@ -33,22 +33,41 @@
allowed_names = ('GET', 'HEAD', 'publishTraverse', 'browserDefault',
'request', '__call__')
+class ResourceFactoryWrapper(object):
+
+ def __init__(self, factory, checker, name):
+ self.__factory = factory
+ self.__checker = checker
+ self.__name = name
+
+ def __call__(self, request):
+ resource = self.__factory(request)
+ resource.__Security_checker__ = self.__checker
+ resource.__name__ = self.__name
+ return resource
+
+
def resource(_context, name, layer=IDefaultBrowserLayer,
- permission='zope.Public', file=None, image=None, template=None):
+ permission='zope.Public', factory=None,
+ file=None, image=None, template=None):
if permission == 'zope.Public':
permission = CheckerPublic
checker = NamesChecker(allowed_names, permission)
- if ((file and image) or (file and template) or
- (image and template) or not (file or image or template)):
+ if (factory and (file or image or template)) or \
+ (file and (factory or image or template)) or \
+ (image and (factory or file or template)) or \
+ (template and (factory or file or image)):
raise ConfigurationError(
- "Must use exactly one of file or image or template"
+ "Must use exactly one of factory or file or image or template"
" attributes for resource directives"
)
- if file:
+ if factory is not None:
+ factory = ResourceFactoryWrapper(factory, checker, name)
+ elif file:
factory = FileResourceFactory(file, checker, name)
elif image:
factory = ImageResourceFactory(image, checker, name)
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2005-02-27 23:12:30 UTC (rev 29327)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2005-02-27 23:28:09 UTC (rev 29328)
@@ -101,6 +101,12 @@
directlyProvides(ITestLayer, ILayer)
+class MyResource(object):
+
+ def __init__(self, request):
+ self.request = request
+
+
class Test(placelesssetup.PlacelessSetup, unittest.TestCase):
def setUp(self):
@@ -815,6 +821,24 @@
name='index.html')
self.assertEqual(v(), 'done')
+ def testFactory(self):
+ self.assertEqual(zapi.queryAdapter(request, name='index.html'), None)
+
+ xmlconfig(StringIO(template %
+ '''
+ <browser:resource
+ name="index.html"
+ factory="
+ zope.app.publisher.browser.tests.test_directives.MyResource"
+ />
+ '''
+ ))
+
+ r = zapi.getAdapter(request, name='index.html')
+ self.assertEquals(r.__class__, MyResource)
+ r = ProxyFactory(r)
+ self.assertEqual(r.__name__, "index.html")
+
def testFile(self):
path = os.path.join(tests_path, 'testfiles', 'test.pt')
More information about the Zope3-Checkins
mailing list