diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt
index d720acc..7e6c4aa 100644
--- a/docs/HISTORY.txt
+++ b/docs/HISTORY.txt
@@ -28,6 +28,10 @@ Changelog
https://github.com/plone/plone.dexterity/pull/11
[malthe]
+- Make it possible to define a SchemaPolicy for the FTI
+ [Frédéric Péters]
+ [gbastien]
+
2.0 (2012-08-30)
----------------
diff --git a/plone/dexterity/fti.py b/plone/dexterity/fti.py
index f5c2e4b..5bff13c 100644
--- a/plone/dexterity/fti.py
+++ b/plone/dexterity/fti.py
@@ -93,7 +93,13 @@ class DexterityFTI(base.DynamicViewTypeInformation):
'description': "Path to file containing the schema model. This can be " +
"relative to a package, e.g. 'my.package:myschema.xml'."
},
-
+ { 'id': 'schema_policy',
+ 'type': 'string',
+ 'mode': 'w',
+ 'label': 'Content type schema policy',
+ 'description': 'Name of the schema policy.'
+ },
+
)
default_aliases = {'(Default)': '(dynamic view)',
@@ -133,6 +139,7 @@ class DexterityFTI(base.DynamicViewTypeInformation):
"""
model_file = u""
schema = u""
+ schema_policy = u"dexterity"
def __init__(self, *args, **kwargs):
super(DexterityFTI, self).__init__(*args, **kwargs)
@@ -224,11 +231,11 @@ class DexterityFTI(base.DynamicViewTypeInformation):
def lookupModel(self):
if self.model_source:
- return loadString(self.model_source, policy=u"dexterity")
+ return loadString(self.model_source, policy=self.schema_policy)
elif self.model_file:
model_file = self._absModelFile()
- return loadFile(model_file, reload=True, policy=u"dexterity")
+ return loadFile(model_file, reload=True, policy=self.schema_policy)
elif self.schema:
schema = self.lookupSchema()
diff --git a/plone/dexterity/tests/test_fti.py b/plone/dexterity/tests/test_fti.py
index 615c5ed..556abb2 100644
--- a/plone/dexterity/tests/test_fti.py
+++ b/plone/dexterity/tests/test_fti.py
@@ -31,6 +31,8 @@ from plone.dexterity.fti import ftiAdded, ftiRemoved, ftiRenamed, ftiModified
from plone.dexterity.factory import DexterityFactory
+from plone.dexterity.schema import DexteritySchemaPolicy
+
from plone.dexterity import utils
from plone.dexterity.tests.schemata import ITestSchema
@@ -46,6 +48,9 @@ class TestClass(object):
class TestClass2(object):
meta_type = "Test Class 2"
+class ITestInterface(Interface):
+ pass
+
class TestFTI(MockTestCase):
@@ -336,6 +341,36 @@ class TestFTI(MockTestCase):
self.assertEquals(u't\xe9st', msgid)
self.assertEquals('test', msgid.domain)
+ def test_lookupModel_without_schema_policy(self):
+ gsm = getGlobalSiteManager()
+ gsm.registerUtility(DexteritySchemaPolicy(), plone.supermodel.interfaces.ISchemaPolicy, name=u"dexterity")
+
+ fti = DexterityFTI(u"testtype")
+ fti.schema = None
+ fti.model_source = ''
+ fti.model_file = None
+
+ model = fti.lookupModel()
+ self.assertEquals(False, ITestInterface in model.schemata[''].__bases__)
+
+ def test_lookupModel_with_schema_policy(self):
+ class TestSchemaPolicy(DexteritySchemaPolicy):
+ def bases(self, schemaName, tree):
+ return (ITestInterface,)
+
+ gsm = getGlobalSiteManager()
+ policy = TestSchemaPolicy()
+ gsm.registerUtility(policy, plone.supermodel.interfaces.ISchemaPolicy, name=u"test")
+
+ fti = DexterityFTI(u"testtype")
+ fti.schema = None
+ fti.model_source = ''
+ fti.model_file = None
+ fti.schema_policy = u"test"
+
+ model = fti.lookupModel()
+ self.assertEquals(True, ITestInterface in model.schemata[''].__bases__)
+
class TestFTIEvents(MockTestCase):