We have a Dexterity-based content type that must inherit a field's default value from its parent. We use the following:
In the model:
<model xmlns="http://ift.tt/VYKrdE"
xmlns:indexer="http://ift.tt/1LEwIBR"
xmlns:form="http://ift.tt/VYKrdG">
<schema>
...
<field name="subjects" type="zope.schema.Tuple" indexer:searchable="true">
...
<defaultFactory>my.package.content.default_subjects</defaultFactory>
...
</field>
</schema>
</model>
The factory is declared like this:
from zope.schema.interfaces import IContextAwareDefaultFactory
...
@provider(IContextAwareDefaultFactory)
def default_subjects(context):
return getattr(context, 'subjects', ())
This works fine when running an instance:
(Pdb) context
<MyType at /Plone/folder>
(Pdb) type(context)
<type 'Acquisition.ImplicitAcquisitionWrapper'>
But fails when running tests as context is not wrapped:
(Pdb) context
<MyType at test>
(Pdb) type(context)
<class 'my.package.content.MyType'>
How can I solve this?
Aucun commentaire:
Enregistrer un commentaire