[Checkins] SVN: z3c.form/trunk/ The AttributeField data manager
wasn't honouring the field's interface
Michael Kerrin
michael.kerrin at openapp.ie
Fri Sep 21 06:29:29 EDT 2007
Log message for revision 79789:
The AttributeField data manager wasn't honouring the field's interface
on the set method also.
Changed:
U z3c.form/trunk/CHANGES.txt
U z3c.form/trunk/src/z3c/form/datamanager.py
U z3c.form/trunk/src/z3c/form/datamanager.txt
-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt 2007-09-21 10:28:21 UTC (rev 79788)
+++ z3c.form/trunk/CHANGES.txt 2007-09-21 10:29:29 UTC (rev 79789)
@@ -11,7 +11,7 @@
the widget. Declared that the widgets require the `zope.Public'
permission in order to access these attributes.
-- Bug: The `canAccess' and `canWrite' methods on the AttributeField
+- Bug: The `canAccess', `canWrite' and `set' methods on the AttributeField
datamanager didn't check for the case when the field's interface was
not directly provided for by the context.
Modified: z3c.form/trunk/src/z3c/form/datamanager.py
===================================================================
--- z3c.form/trunk/src/z3c/form/datamanager.py 2007-09-21 10:28:21 UTC (rev 79788)
+++ z3c.form/trunk/src/z3c/form/datamanager.py 2007-09-21 10:29:29 UTC (rev 79789)
@@ -63,7 +63,9 @@
self.context.__class__.__module__,
self.context.__class__.__name__))
# get the right adapter or context
- context = self.field.interface(self.context)
+ context = self.context
+ if self.field.interface is not None:
+ context = self.field.interface(context)
setattr(context, self.field.__name__, value)
def canAccess(self):
Modified: z3c.form/trunk/src/z3c/form/datamanager.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/datamanager.txt 2007-09-21 10:28:21 UTC (rev 79788)
+++ z3c.form/trunk/src/z3c/form/datamanager.txt 2007-09-21 10:29:29 UTC (rev 79789)
@@ -216,7 +216,7 @@
that we will eventually provide alternative ways to accomplish the same in a
more explicit way.
-Finally, if we try to set a value that is read-only, a type error is raised:
+If we try to set a value that is read-only, a type error is raised:
>>> readOnlyName = zope.schema.TextLine(
... __name__='name',
@@ -229,7 +229,25 @@
TypeError: Can't set values on read-only fields
(name=name, class=__builtin__.Person)
+Finally, we instantiate the data manager with a `zope.schema'
+field. And we can access the different methods like before.
+ >>> nameDm = datamanager.AttributeField(
+ ... stephan, zope.schema.TextLine(__name__ = 'name'))
+ >>> nameDm.canAccess()
+ True
+ >>> nameDm.canWrite()
+ True
+
+ >>> nameDm.get()
+ u'Stephan "Caveman" Richter'
+ >>> nameDm.query()
+ u'Stephan "Caveman" Richter'
+
+ >>> nameDm.set(u'Stephan Richter')
+ >>> nameDm.get()
+ u'Stephan Richter'
+
Dictionary Field Manager
------------------------
More information about the Checkins
mailing list