[Zope3-checkins] SVN: Zope3/branches/3.3/ - fixed issue 199: macro
expansion in ZPT pages now works
Christian Theune
cvs-admin at zope.org
Fri Jun 16 22:25:43 EDT 2006
Log message for revision 68696:
- fixed issue 199: macro expansion in ZPT pages now works
Changed:
U Zope3/branches/3.3/doc/CHANGES.txt
U Zope3/branches/3.3/src/zope/app/zptpage/browser/configure.zcml
U Zope3/branches/3.3/src/zope/app/zptpage/browser/ftests.py
U Zope3/branches/3.3/src/zope/app/zptpage/browser/zptpage.py
U Zope3/branches/3.3/src/zope/app/zptpage/zptpage.py
U Zope3/branches/3.3/src/zope/pagetemplate/pagetemplate.py
-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt 2006-06-16 21:05:38 UTC (rev 68695)
+++ Zope3/branches/3.3/doc/CHANGES.txt 2006-06-17 02:25:39 UTC (rev 68696)
@@ -10,6 +10,8 @@
Bugfixes
+ - Fixed issue 199: macro expansion in ZPT pages now work
+
- Fixed issues 648 and 593: uploading files with non-ASCII filenames now
works.
Modified: Zope3/branches/3.3/src/zope/app/zptpage/browser/configure.zcml
===================================================================
--- Zope3/branches/3.3/src/zope/app/zptpage/browser/configure.zcml 2006-06-16 21:05:38 UTC (rev 68695)
+++ Zope3/branches/3.3/src/zope/app/zptpage/browser/configure.zcml 2006-06-17 02:25:39 UTC (rev 68696)
@@ -36,12 +36,10 @@
permission="zope.ManageContent"
/>
- <browser:editform
+ <browser:page
for="zope.app.zptpage.interfaces.IZPTPage"
- schema="zope.app.zptpage.interfaces.IZPTPage"
name="edit.html"
- label="Edit a ZPT page"
- fields="source expand"
+ class=".zptpage.EditForm"
permission="zope.ManageContent"
menu="zmi_views" title="Edit"
/>
Modified: Zope3/branches/3.3/src/zope/app/zptpage/browser/ftests.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/zptpage/browser/ftests.py 2006-06-16 21:05:38 UTC (rev 68695)
+++ Zope3/branches/3.3/src/zope/app/zptpage/browser/ftests.py 2006-06-17 02:25:39 UTC (rev 68696)
@@ -93,7 +93,6 @@
basic='mgr:mgrpw')
self.assertEqual(response.getStatus(), 200)
body = response.getBody()
- self.assert_('Edit a ZPT page' in body)
self.assert_('Source' in body)
self.assert_('Expand macros' in body)
self.assert_(escape(self.content) in body)
@@ -104,20 +103,43 @@
self.addZPTPage()
response = self.publish(
'/zptpage/@@edit.html',
- form={'field.source': u'<h1>A ZPT Page</h1>\n',
- 'field.expand.used': u'',
- 'field.expand': u'on',
- 'UPDATE_SUBMIT': u'Edit'},
+ form={'form.source': u'<h1>A ZPT Page</h1>\n',
+ 'form.expand.used': u'',
+ 'form.expand': u'on',
+ 'form.actions.apply': u'Apply'},
basic='mgr:mgrpw')
self.assertEqual(response.getStatus(), 200)
body = response.getBody()
- self.assert_('Edit a ZPT page' in body)
self.assert_('Source' in body)
self.assert_(escape(u'<h1>A ZPT Page</h1>') in body)
root = self.getRootFolder()
zptpage = root['zptpage']
self.assertEqual(zptpage.source, '<h1>A ZPT Page</h1>\n')
self.assertEqual(zptpage.expand, True)
+
+ def testIssue199(self):
+ # This is a test to protect us against issue 199 in the future
+ self.addZPTPage()
+ source = u"""<html metal:use-macro="container/@@standard_macros/page">
+ <body>
+ <div metal:fill-slot="body">
+ write this in the body slot.
+ </div>
+ </body>
+ </html>"""
+
+ response = self.publish(
+ '/zptpage/@@edit.html',
+ form={'form.source': source,
+ 'form.expand.used': u'',
+ 'form.expand': u'on',
+ 'form.actions.apply': u'Apply'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ # Check for a string from the default template
+ self.assert_(escape(u'Z3 UI') in body)
+ self.failIf(u"Macro expansion failed" in body)
def testIndex(self):
self.addZPTPage()
Modified: Zope3/branches/3.3/src/zope/app/zptpage/browser/zptpage.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/zptpage/browser/zptpage.py 2006-06-16 21:05:38 UTC (rev 68695)
+++ Zope3/branches/3.3/src/zope/app/zptpage/browser/zptpage.py 2006-06-17 02:25:39 UTC (rev 68696)
@@ -15,6 +15,11 @@
$Id$
"""
+
+import zope.formlib.form
+
+import zope.app.zptpage.interfaces
+
class ZPTPageEval(object):
def index(self, **kw):
@@ -27,3 +32,24 @@
template.content_type)
return template.render(request, **kw)
+
+class EditForm(zope.formlib.form.EditForm):
+ """Edit form for ZPT pages."""
+
+ form_fields = zope.formlib.form.Fields(
+ zope.app.zptpage.interfaces.IZPTPage,
+ render_context=True).omit('evaluateInlineCode')
+
+ def setUpWidgets(self, ignore_request=False):
+ self.adapters = {}
+
+ # We need to extract the data directly, as we can not pass on the
+ # request for macro expansion otherwise.
+ data = {}
+ data['source'] = self.context.getSource(self.request)
+
+ self.widgets = zope.formlib.form.setUpWidgets(
+ self.form_fields, self.prefix, self.context, self.request,
+ data=data, form=self, adapters=self.adapters,
+ ignore_request=ignore_request)
+
Modified: Zope3/branches/3.3/src/zope/app/zptpage/zptpage.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/zptpage/zptpage.py 2006-06-16 21:05:38 UTC (rev 68695)
+++ Zope3/branches/3.3/src/zope/app/zptpage/zptpage.py 2006-06-17 02:25:39 UTC (rev 68696)
@@ -42,9 +42,9 @@
# See zope.app.zptpage.interfaces.IZPTPage
evaluateInlineCode = False
- def getSource(self):
+ def getSource(self, request=None):
"""See zope.app.zptpage.interfaces.IZPTPage"""
- return self.read()
+ return self.read(request)
def setSource(self, text, content_type='text/html'):
"""See zope.app.zptpage.interfaces.IZPTPage"""
Modified: Zope3/branches/3.3/src/zope/pagetemplate/pagetemplate.py
===================================================================
--- Zope3/branches/3.3/src/zope/pagetemplate/pagetemplate.py 2006-06-16 21:05:38 UTC (rev 68695)
+++ Zope3/branches/3.3/src/zope/pagetemplate/pagetemplate.py 2006-06-17 02:25:39 UTC (rev 68696)
@@ -150,7 +150,7 @@
# the content-type might have changed.
self._cook()
- def read(self):
+ def read(self, request=None):
"""Gets the source, sometimes with macros expanded."""
self._cook_check()
if not self._v_errors:
@@ -160,7 +160,7 @@
# This gets called, if macro expansion is turned on.
# Note that an empty dictionary is fine for the context at
# this point, since we are not evaluating the template.
- return self.pt_render(self.pt_getContext(self, None), source=1)
+ return self.pt_render(self.pt_getContext(self, request), source=1)
except:
return ('%s\n Macro expansion failed\n %s\n-->\n%s' %
(_error_start, "%s: %s" % sys.exc_info()[:2],
More information about the Zope3-Checkins
mailing list