[Checkins] SVN: zope.fanstatic/trunk/ Use zope.errorview in order to clear the needed resources when an exception view is rendered.
Jan-Jaap Driessen
jdriessen at thehealthagency.com
Wed Jan 19 09:50:30 EST 2011
Log message for revision 119709:
Use zope.errorview in order to clear the needed resources when an exception view is rendered.
Changed:
U zope.fanstatic/trunk/buildout.cfg
U zope.fanstatic/trunk/setup.py
U zope.fanstatic/trunk/src/zope/fanstatic/README.txt
U zope.fanstatic/trunk/src/zope/fanstatic/configure.zcml
U zope.fanstatic/trunk/src/zope/fanstatic/tests/ftesting.zcml
A zope.fanstatic/trunk/src/zope/fanstatic/tests/test_error.pt
U zope.fanstatic/trunk/src/zope/fanstatic/tests/view.py
U zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py
-=-
Modified: zope.fanstatic/trunk/buildout.cfg
===================================================================
--- zope.fanstatic/trunk/buildout.cfg 2011-01-19 14:43:10 UTC (rev 119708)
+++ zope.fanstatic/trunk/buildout.cfg 2011-01-19 14:50:30 UTC (rev 119709)
@@ -6,7 +6,12 @@
parts = test
versions = versions
allow-picked-versions = false
+extensions = mr.developer
+auto-checkout = zope.errorview
+[sources]
+zope.errorview = svn svn+ssh://svn.zope.org/repos/main/zope.errorview/trunk
+
[versions]
zope.app.wsgi = 3.10.0
WebOb = 1.0
Modified: zope.fanstatic/trunk/setup.py
===================================================================
--- zope.fanstatic/trunk/setup.py 2011-01-19 14:43:10 UTC (rev 119708)
+++ zope.fanstatic/trunk/setup.py 2011-01-19 14:50:30 UTC (rev 119709)
@@ -33,6 +33,8 @@
'setuptools',
'fanstatic',
'zope.component',
+ 'zope.errorview',
+ 'zope.event',
'zope.interface',
'zope.publisher',
'zope.traversing',
Modified: zope.fanstatic/trunk/src/zope/fanstatic/README.txt
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/README.txt 2011-01-19 14:43:10 UTC (rev 119708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/README.txt 2011-01-19 14:50:30 UTC (rev 119709)
@@ -2,13 +2,14 @@
******************************
This package provides Zope integration for fanstatic. This means it's
-taking care of two things:
+taking care of three things:
-* provide access to the needed resources throughout the
- request/response cycle.
+* provide access to the needed resources throughout the request/response cycle.
* provide the base URL for the resources to be rendered.
+* clear the needed resources when an exception view is rendered.
+
This library fulfills these conditions for a Zope Toolkit/Grok setup.
We'll run through a few tests to demonstrate it. Note that the real
@@ -81,4 +82,17 @@
</body>
</html>
+Exception views
+---------------
+When an exception occurs in the rendering of a view, we don't want to have any
+needed resources intended for a view being also injected in the error view.
+The needed resources are cleared and if the exception view chooses to do so,
+it can need resources itself.
+
+ >>> browser.raiseHttpErrors = False
+ >>> browser.open('http://localhost/zope.fanstatic.test_error')
+ >>> import fanstatic
+ >>> fanstatic.get_needed().has_resources()
+ False
+
Modified: zope.fanstatic/trunk/src/zope/fanstatic/configure.zcml
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/configure.zcml 2011-01-19 14:43:10 UTC (rev 119708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/configure.zcml 2011-01-19 14:50:30 UTC (rev 119709)
@@ -4,11 +4,13 @@
xmlns:zf="http://namespaces.zope.org/zf">
<include package="zope.component" file="meta.zcml" />
-
<include package="zope.fanstatic" file="meta.zcml" />
+ <include package="zope.errorview" file="browser.zcml" />
<zf:setupZopeFanstatic />
- <subscriber handler=".zopesupport.set_base_url_on_needed_inclusions" />
+ <subscriber handler=".zopesupport.set_base_url" />
+ <subscriber handler=".zopesupport.clear_needed_resources" />
+
</configure>
Modified: zope.fanstatic/trunk/src/zope/fanstatic/tests/ftesting.zcml
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/tests/ftesting.zcml 2011-01-19 14:43:10 UTC (rev 119708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/tests/ftesting.zcml 2011-01-19 14:50:30 UTC (rev 119709)
@@ -81,4 +81,12 @@
class=".view.TestInlineResource"
/>
+ <browser:page
+ for="zope.interface.Interface"
+ name="zope.fanstatic.test_error"
+ permission="zope.Public"
+ template="test_error.pt"
+ class=".view.TestError"
+ />
+
</configure>
Added: zope.fanstatic/trunk/src/zope/fanstatic/tests/test_error.pt
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/tests/test_error.pt (rev 0)
+++ zope.fanstatic/trunk/src/zope/fanstatic/tests/test_error.pt 2011-01-19 14:50:30 UTC (rev 119709)
@@ -0,0 +1,7 @@
+<html>
+<head>
+</head>
+<body>
+<p tal:content="view/widget"></p>
+</body>
+</html>
Modified: zope.fanstatic/trunk/src/zope/fanstatic/tests/view.py
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/tests/view.py 2011-01-19 14:43:10 UTC (rev 119708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/tests/view.py 2011-01-19 14:50:30 UTC (rev 119709)
@@ -30,3 +30,8 @@
class TestInlineResource(object):
pass
+class TestError(object):
+ def widget(self):
+ b.need()
+ raise Exception('I am not a teapot')
+
Modified: zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py 2011-01-19 14:43:10 UTC (rev 119708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py 2011-01-19 14:50:30 UTC (rev 119709)
@@ -4,13 +4,14 @@
from zope.traversing.browser.absoluteurl import absoluteURL
from zope.traversing.browser.interfaces import IAbsoluteURL
from zope.traversing.interfaces import ITraversable
+from zope.errorview.interfaces import IHandleExceptionEvent
import fanstatic
from zope.fanstatic.interfaces import IZopeFanstaticResource
@adapter(IEndRequestEvent)
-def set_base_url_on_needed_inclusions(event):
+def set_base_url(event):
# At first sight it might be better to subscribe to the
# IBeforeTraverseEvent for ISite objects and only set a base_url
# then. However, we might be too early in that case and miss out
@@ -35,6 +36,10 @@
# enough.
needed.base_url = absoluteURL(None, event.request)
+ at adapter(IHandleExceptionEvent)
+def clear_needed_resources(event):
+ fanstatic.clear_needed()
+
_sentinel = object()
class ZopeFanstaticResource(object):
More information about the checkins
mailing list