[Checkins] SVN: plone.z3cform/trunk/ make tests work on Plone 3 since optilude's refactoring; also make a form wrapper unnecessary by giving forms a full acquisition chain
David Glick
davidglick at onenw.org
Sun Feb 21 23:58:48 EST 2010
Log message for revision 109244:
make tests work on Plone 3 since optilude's refactoring; also make a form wrapper unnecessary by giving forms a full acquisition chain
Changed:
U plone.z3cform/trunk/docs/HISTORY.txt
U plone.z3cform/trunk/plone/z3cform/fieldsets/README.txt
U plone.z3cform/trunk/plone/z3cform/templates.py
-=-
Modified: plone.z3cform/trunk/docs/HISTORY.txt
===================================================================
--- plone.z3cform/trunk/docs/HISTORY.txt 2010-02-22 02:00:58 UTC (rev 109243)
+++ plone.z3cform/trunk/docs/HISTORY.txt 2010-02-22 04:58:45 UTC (rev 109244)
@@ -4,8 +4,13 @@
0.5.11 - unreleased
-------------------
-* Nothing changed yet.
+* Fixed tests in Plone 3.
+* Make it possible to use z3c.form forms without a FormWrapper in Plone 3.
+ [davisagli]
+
+* [placeholder for optilude's changelog]
+
0.5.10 - 2010-02-01
-------------------
Modified: plone.z3cform/trunk/plone/z3cform/fieldsets/README.txt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/fieldsets/README.txt 2010-02-22 02:00:58 UTC (rev 109243)
+++ plone.z3cform/trunk/plone/z3cform/fieldsets/README.txt 2010-02-22 04:58:45 UTC (rev 109244)
@@ -22,8 +22,12 @@
... title = schema.TextLine(title=u"Title")
>>> class Test(object):
+ ... # avoid needing an acl_users for this test in Zope 2.10
+ ... __allow_access_to_unprotected_subobjects__ = 1
... implements(ITest, IAttributeAnnotatable)
... title = u""
+ ... def getPhysicalRoot(self): # needed for template to acquire REQUEST in Zope 2.10
+ ... return self
>>> class TestForm(extensible.ExtensibleForm, form.Form):
... fields = field.Fields(ITest)
@@ -31,14 +35,22 @@
Here, note the order of the base classes. Also note that we use an ordinary
set of fields directly on the form. This known as the default fieldset.
-This form should work as-is, i.e. we can update it:
+This form should work as-is, i.e. we can update it. First we need to fake a
+request.
>>> from z3c.form.testing import TestRequest
>>> request = TestRequest()
+ >>> request.other = {}
>>> context = Test()
+ >>> context.REQUEST = request
>>> form = TestForm(context, request)
+ >>> try: # Zope 2.10 templates need a proper acquisition chain
+ ... from Acquisition import ImplicitAcquisitionWrapper
+ ... form = ImplicitAcquisitionWrapper(form, context)
+ ... except:
+ ... pass
>>> form.update()
>>> _ = form.render()
Modified: plone.z3cform/trunk/plone/z3cform/templates.py
===================================================================
--- plone.z3cform/trunk/plone/z3cform/templates.py 2010-02-22 02:00:58 UTC (rev 109243)
+++ plone.z3cform/trunk/plone/z3cform/templates.py 2010-02-22 04:58:45 UTC (rev 109244)
@@ -5,6 +5,8 @@
itself to render parts of it.
"""
+from Acquisition import IAcquirer, ImplicitAcquisitionWrapper
+
import os
import zope.publisher.browser
import zope.app.pagetemplate.viewpagetemplatefile
@@ -47,7 +49,7 @@
util.getSpecification(form),
util.getSpecification(request))(self)
zope.interface.implementer(IPageTemplate)(self)
-
+
class ZopeTwoFormTemplateFactory(z3c.form.form.FormTemplateFactory):
"""Form template factory for Zope 2 page templates.
@@ -62,6 +64,13 @@
util.getSpecification(request))(self)
zope.interface.implementer(IPageTemplate)(self)
+ def __call__(self, form, request):
+ template = self.template
+ if IAcquirer.providedBy(template):
+ return ImplicitAcquisitionWrapper(template, form)
+ else:
+ return template
+
class ZopeTwoWidgetTemplateFactory(z3c.form.widget.WidgetTemplateFactory):
"""A variant of z3c.form's widget.WidgetTemplateFactory which uses Zope 2
page templates. This should only be necessary if you strictly need the
More information about the checkins
mailing list