[Checkins] SVN: z3c.form/trunk/ merged icemac-dm-query branch
Michael Howitz
mh at gocept.com
Sun Jul 18 14:58:01 EDT 2010
Log message for revision 114824:
merged icemac-dm-query branch
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/src/z3c/form/form.py
A z3c.form/trunk/src/z3c/form/tests/test_bugfix.py
U z3c.form/trunk/src/z3c/form/util.txt
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2010-07-18 18:50:40 UTC (rev 114823)
+++ z3c.form/trunk/CHANGES.txt 2010-07-18 18:58:01 UTC (rev 114824)
@@ -5,6 +5,13 @@
2.4.1 (unreleased)
------------------
+- Since version 2.3.4 ``applyChanges`` required that the value exists
+ when the field had a ``DictionaryField`` data manager otherwise it
+ broke with an ``AttributeError``. Restored previous behavior that
+ values need not to be exist before ``applyChanges`` was called by
+ using ``datamanager.query()`` instead of ``datamanager.get()`` to
+ get the previous value.
+
- Added missing dependency on ``zope.contentprovider``.
Modified: z3c.form/trunk/src/z3c/form/form.py
===================================================================
--- z3c.form/trunk/src/z3c/form/form.py 2010-07-18 18:50:40 UTC (rev 114823)
+++ z3c.form/trunk/src/z3c/form/form.py 2010-07-18 18:58:01 UTC (rev 114824)
@@ -46,8 +46,8 @@
# Only update the data, if it is different
# Or we can not get the original value, in which case we can not check
# Or it is an Object, in case we'll never know
- if (not dm.canAccess() or
- dm.get() != data[name] or
+ if (not dm.canAccess() or
+ dm.query() != data[name] or
zope.schema.interfaces.IObject.providedBy(field.field)):
dm.set(data[name])
# Record the change using information required later
@@ -213,11 +213,11 @@
def __call__(self):
self.update()
-
+
# Don't render anything if we are doing a redirect
if self.request.response.getStatus() in (300, 301, 302, 303, 304, 305, 307,):
return u''
-
+
return self.render()
Copied: z3c.form/trunk/src/z3c/form/tests/test_bugfix.py (from rev 114644, z3c.form/branches/icemac-dm-query/src/z3c/form/tests/test_bugfix.py)
===================================================================
--- z3c.form/trunk/src/z3c/form/tests/test_bugfix.py (rev 0)
+++ z3c.form/trunk/src/z3c/form/tests/test_bugfix.py 2010-07-18 18:58:01 UTC (rev 114824)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation 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.
+#
+##############################################################################
+"""Unittests for bug fixes."""
+
+import unittest
+
+class TestApplyChangesDictDatamanager(unittest.TestCase):
+ # z3c.form.form.applyChanges could not write a value into an empty
+ # content dict it got an AttributeError while accessing
+ # datamanger.get(). This test makes sure that a dictionary content
+ # does not need to be initialized with all keys which might be
+ # written on it later on. (This was the behavior before
+ # datamanger.DictionaryField.get() raised an AttributeError on not
+ # existing keys.
+
+ def setUp(self):
+ import zope.component
+ import zope.interface
+ import z3c.form.datamanager
+
+ zope.component.provideAdapter(
+ z3c.form.datamanager.DictionaryField,
+ (dict, zope.interface.Interface))
+
+ def tearDown(self):
+ import zope.component.globalregistry
+ import z3c.form.datamanager
+
+ zope.component.globalregistry.getGlobalSiteManager().unregisterAdapter(
+ z3c.form.datamanager.DictionaryField,
+ (dict, zope.interface.Interface))
+
+ def test_applyChanges(self):
+ import z3c.form.field
+ import z3c.form.form
+ import zope.schema
+ import zope.interface
+
+ class TestInterface(zope.interface.Interface):
+ text = zope.schema.TextLine(title=u'text')
+
+ class TestForm(z3c.form.form.BaseForm):
+ fields = z3c.form.field.Fields(TestInterface)
+
+ # content is an empty dict, the `text` key does not yet exist
+ content = dict()
+ form = TestForm(content, request=None)
+ data = dict(text='a')
+ changes = z3c.form.form.applyChanges(form, content, data)
+ self.assertEqual({TestInterface: ['text']}, changes)
+ self.assertEqual({'text': 'a'}, content)
Modified: z3c.form/trunk/src/z3c/form/util.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/util.txt 2010-07-18 18:50:40 UTC (rev 114823)
+++ z3c.form/trunk/src/z3c/form/util.txt 2010-07-18 18:58:01 UTC (rev 114824)
@@ -8,8 +8,8 @@
>>> from z3c.form import util
-``creeateId(name)`` Function
-----------------------------
+``createId(name)`` Function
+---------------------------
This function converts an arbitrary unicode string into a valid Python
identifier. If the name is a valid identifier, then it is just returned, but
@@ -408,15 +408,15 @@
>>> import zope.interface
>>> class IFoo(zope.interface.Interface):
... pass
-
+
>>> util.getSpecification(IFoo) == IFoo
True
-
+
Ditto for a class:
-
+
>>> class Bar(object):
... pass
-
+
>>> util.getSpecification(Bar) == Bar
True
@@ -440,6 +440,6 @@
False
>>> bazMarker1 == bazMarker2
- True
+ True
>>> bazMarker1 is bazMarker2
True
More information about the checkins
mailing list