Skip to content

Commit

Permalink
merged icemac-dm-query branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Jul 18, 2010
2 parents 0df8a13 + a84d7bb commit b82ba74
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,13 @@ CHANGES
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``.


Expand Down
8 changes: 4 additions & 4 deletions src/z3c/form/form.py
Expand Up @@ -46,8 +46,8 @@ def applyChanges(form, content, data):
# 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
Expand Down Expand Up @@ -213,11 +213,11 @@ def update(self):

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()


Expand Down
62 changes: 62 additions & 0 deletions src/z3c/form/tests/test_bugfix.py
@@ -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)
14 changes: 7 additions & 7 deletions src/z3c/form/util.txt
Expand Up @@ -8,8 +8,8 @@ tested.
>>> 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
Expand Down Expand Up @@ -408,15 +408,15 @@ For an interface, it simply returns the interface:
>>> 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

Expand All @@ -440,6 +440,6 @@ marker each time:
False

>>> bazMarker1 == bazMarker2
True
True
>>> bazMarker1 is bazMarker2
True

0 comments on commit b82ba74

Please sign in to comment.