Default attribute accessor now returns a field default for a field provided by a subtype.
This commit is contained in:
parent
26d27cb66f
commit
dd491480b8
|
@ -4,6 +4,10 @@ Changelog
|
|||
2.0.1 (unreleased)
|
||||
------------------
|
||||
|
||||
- The default attribute accessor now also looks through subtypes
|
||||
(behaviors) to find a field default.
|
||||
[malthe]
|
||||
|
||||
- Added support in the FTI to look up behaviors by utility name when
|
||||
getting additional schemata (i.e. fields provided by behaviors).
|
||||
|
||||
|
|
|
@ -186,6 +186,12 @@ class DexterityContent(DAVResourceMixin, PortalContent, DefaultDublinCoreImpl, C
|
|||
if field is not None:
|
||||
return deepcopy(field.default)
|
||||
|
||||
# do the same for each subtype
|
||||
for schema in SCHEMA_CACHE.subtypes(self.portal_type):
|
||||
field = schema.get(name, None)
|
||||
if field is not None:
|
||||
return deepcopy(field.default)
|
||||
|
||||
raise AttributeError(name)
|
||||
|
||||
# Let __name__ and id be identical. Note that id must be ASCII in Zope 2,
|
||||
|
|
|
@ -231,7 +231,7 @@ class TestContent(MockTestCase):
|
|||
pass
|
||||
|
||||
class ISubtype(Interface):
|
||||
pass
|
||||
baz = zope.schema.TextLine(title=u"baz", default=u"baz")
|
||||
|
||||
behavior1 = BehaviorRegistration(u"Behavior1", "", IBehavior1, None, None)
|
||||
behavior2 = BehaviorRegistration(u"Behavior2", "", IBehavior2, ISubtype, None)
|
||||
|
@ -259,6 +259,9 @@ class TestContent(MockTestCase):
|
|||
self.assertEquals(True, ISubtype.providedBy(item))
|
||||
self.assertEquals(True, ISchema.providedBy(item))
|
||||
|
||||
# Subtypes provide field defaults.
|
||||
self.assertEquals(u"baz", getattr(item, "baz", None))
|
||||
|
||||
# We also need to ensure that the _v_ attribute doesn't hide any
|
||||
# interface set directly on the instance with alsoProvides() or
|
||||
# directlyProvides(). This is done by clearing the cache when these
|
||||
|
|
Reference in New Issue