From afb4b96ebf24e28c992f216a9a6cdc018e74cda9 Mon Sep 17 00:00:00 2001 From: Frederic Peters Date: Thu, 13 Dec 2012 17:25:47 +0100 Subject: [PATCH 1/3] Add a schema policy attribute to Dexterity FTI --- plone/dexterity/fti.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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() From 6778c2c23b6c6c26bf4100615159736ac84f4b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 14 Dec 2012 15:05:37 +0100 Subject: [PATCH 2/3] Add tests for the schema_policy attribute --- plone/dexterity/tests/test_fti.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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): From ff16a44ae72e2b36050402f960245f7a1ebca245 Mon Sep 17 00:00:00 2001 From: Gauthier Bastien Date: Mon, 17 Dec 2012 14:08:28 +0100 Subject: [PATCH 3/3] Update docs/HISTORY.txt --- docs/HISTORY.txt | 4 ++++ 1 file changed, 4 insertions(+) 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) ----------------