[Checkins] SVN: z3c.form/trunk/src/z3c/form/ During the get value routine in widgets, replaced the get() method by
Hermann Himmelbauer
dusty at qwer.tk
Tue Aug 26 10:11:44 EDT 2008
Log message for revision 90332:
During the get value routine in widgets, replaced the get() method by
query(), so that missing attributes will not lead to a traceback.
Altered query method of attribute data manager - an error is raised for
forbidden attributes, while the default value is returned if no
attribute is available.
Updated the interfaces, so that they reflect the datamanagers
query() method.
Fixed a small typo in the doctest.
Changed:
U z3c.form/trunk/src/z3c/form/datamanager.py
U z3c.form/trunk/src/z3c/form/interfaces.py
U z3c.form/trunk/src/z3c/form/widget.py
U z3c.form/trunk/src/z3c/form/widget.txt
-=-
Modified: z3c.form/trunk/src/z3c/form/datamanager.py
===================================================================
--- z3c.form/trunk/src/z3c/form/datamanager.py 2008-08-26 13:40:52 UTC (rev 90331)
+++ z3c.form/trunk/src/z3c/form/datamanager.py 2008-08-26 14:11:43 UTC (rev 90332)
@@ -20,6 +20,7 @@
import zope.interface
import zope.component
import zope.schema
+from zope.security.interfaces import ForbiddenAttribute
from zope.security.checker import canAccess, canWrite, Proxy
from z3c.form import interfaces
@@ -29,7 +30,6 @@
"""Data manager base class."""
zope.interface.implements(interfaces.IDataManager)
-
class AttributeField(DataManager):
"""Attribute field."""
zope.component.adapts(
@@ -51,6 +51,8 @@
"""See z3c.form.interfaces.IDataManager"""
try:
return self.get()
+ except ForbiddenAttribute, e:
+ raise e
except AttributeError:
return default
Modified: z3c.form/trunk/src/z3c/form/interfaces.py
===================================================================
--- z3c.form/trunk/src/z3c/form/interfaces.py 2008-08-26 13:40:52 UTC (rev 90331)
+++ z3c.form/trunk/src/z3c/form/interfaces.py 2008-08-26 14:11:43 UTC (rev 90332)
@@ -223,10 +223,17 @@
class IDataManager(zope.interface.Interface):
"""Data manager."""
- def get(default=NOVALUE):
+ def get():
"""Get the value.
+ If no value can be found, raise an error
+ """
+
+ def query(default=NOVALUE):
+ """Get the value.
+
If no value can be found, return the default value.
+ If access is forbidden, raise an error.
"""
def set(value):
Modified: z3c.form/trunk/src/z3c/form/widget.py
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.py 2008-08-26 13:40:52 UTC (rev 90331)
+++ z3c.form/trunk/src/z3c/form/widget.py 2008-08-26 14:11:43 UTC (rev 90332)
@@ -94,7 +94,8 @@
if (interfaces.IContextAware.providedBy(self) and
not self.ignoreContext):
value = zope.component.getMultiAdapter(
- (self.context, self.field), interfaces.IDataManager).get()
+ (self.context, self.field),
+ interfaces.IDataManager).query()
# Step 1.2.2: If we still do not have a value, we can always use
# the default value of the field, id set
# NOTE: It should check field.default is not missing_value, but
Modified: z3c.form/trunk/src/z3c/form/widget.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/widget.txt 2008-08-26 13:40:52 UTC (rev 90331)
+++ z3c.form/trunk/src/z3c/form/widget.txt 2008-08-26 14:11:43 UTC (rev 90332)
@@ -262,7 +262,7 @@
>>> print ageWidget.render()
<input type="text" name="age" value="25" />
-But what happens if the object we are working on is securoty proxied? In
+But what happens if the object we are working on is security proxied? In
particular, what happens, if the access to the attribute is denied. To see
what happens, we have to create a proxied person:
More information about the Checkins
mailing list