[Zope3-checkins] SVN: Zope3/branches/3.2/ Ported revision 40640
from the trunk, which fixes the FieldProperty's use
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Jan 4 10:47:28 EST 2006
Log message for revision 41134:
Ported revision 40640 from the trunk, which fixes the FieldProperty's use
of the readonly option of fields.
Changed:
U Zope3/branches/3.2/doc/CHANGES.txt
U Zope3/branches/3.2/src/zope/schema/fieldproperty.py
U Zope3/branches/3.2/src/zope/schema/tests/test_fieldproperty.py
-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt 2006-01-04 15:19:13 UTC (rev 41133)
+++ Zope3/branches/3.2/doc/CHANGES.txt 2006-01-04 15:47:27 UTC (rev 41134)
@@ -8,6 +8,10 @@
since Zope 3.2.0b3
+ Bug Fixes
+
+ - Fixed a bug in FieldProperty to honor the readonly field.
+
Zope 3.2.0b3
Bug Fixes
Modified: Zope3/branches/3.2/src/zope/schema/fieldproperty.py
===================================================================
--- Zope3/branches/3.2/src/zope/schema/fieldproperty.py 2006-01-04 15:19:13 UTC (rev 41133)
+++ Zope3/branches/3.2/src/zope/schema/fieldproperty.py 2006-01-04 15:47:27 UTC (rev 41134)
@@ -50,6 +50,8 @@
def __set__(self, inst, value):
field = self.__field.bind(inst)
field.validate(value)
+ if field.readonly and inst.__dict__.has_key(self.__name):
+ raise ValueError(self.__name, 'field is readonly')
inst.__dict__[self.__name] = value
def __getattr__(self, name):
Modified: Zope3/branches/3.2/src/zope/schema/tests/test_fieldproperty.py
===================================================================
--- Zope3/branches/3.2/src/zope/schema/tests/test_fieldproperty.py 2006-01-04 15:19:13 UTC (rev 41133)
+++ Zope3/branches/3.2/src/zope/schema/tests/test_fieldproperty.py 2006-01-04 15:47:27 UTC (rev 41134)
@@ -28,16 +28,19 @@
title = Text(description=u"Short summary", default=u'say something')
weight = Float(min=0.0)
code = Bytes(min_length=6, max_length=6, default='xxxxxx')
+ date = Float(title=u'Date', readonly=True)
+
class C(object):
title = FieldProperty(I['title'])
weight = FieldProperty(I['weight'])
code = FieldProperty(I['code'])
+ date = FieldProperty(I['date'])
class Test(TestCase):
- def test(self):
+ def test_basic(self):
c = C()
self.assertEqual(c.title, u'say something')
self.assertEqual(c.weight, None)
@@ -58,6 +61,12 @@
self.assertEqual(c.weight, 10)
self.assertEqual(c.code, 'abcdef')
+ def test_readonly(self):
+ c = C()
+ # The date should be only settable once
+ c.date = 0.0
+ # Setting the value a second time should fail.
+ self.assertRaises(ValueError, setattr, c, 'date', 1.0)
def test_suite():
More information about the Zope3-Checkins
mailing list