Use objects factory to create configuration objects
authortflorac@dagon.home
Sun, 17 Jun 2018 16:29:00 +0200
changeset 347 fbdccca7bad5
parent 346 e6fb4dbdda28
child 348 b3c4d616ff30
Use objects factory to create configuration objects
src/pyams_skin/configuration.py
--- a/src/pyams_skin/configuration.py	Sun Jun 17 16:10:19 2018 +0200
+++ b/src/pyams_skin/configuration.py	Sun Jun 17 16:29:00 2018 +0200
@@ -19,7 +19,7 @@
 from pyams_skin.interfaces import IContextTitlePrefix
 from pyams_skin.interfaces.configuration import IConfiguration, SKIN_CONFIGURATION_KEY, \
     IBackOfficeConfiguration, SKIN_BACK_CONFIGURATION_KEY
-from pyams_utils.interfaces.site import IConfigurationManager, IConfigurationFactory, IBackOfficeConfigurationFactory
+from pyams_utils.interfaces.site import IConfigurationManager
 from pyams_utils.interfaces.tales import ITALESExtension
 from zope.traversing.interfaces import ITraversable
 
@@ -28,6 +28,7 @@
 from pyams_file.property import FileProperty
 from pyams_file.views.file import FileView
 from pyams_utils.adapter import ContextRequestViewAdapter, ContextAdapter, adapter_config, get_annotation_adapter
+from pyams_utils.factory import factory_config
 from pyams_utils.registry import get_global_registry
 from pyams_utils.traversing import get_parent
 from pyramid.httpexceptions import HTTPNotFound
@@ -43,6 +44,7 @@
 #
 
 @implementer(IConfiguration)
+@factory_config(provided=IConfiguration)
 class Configuration(Persistent, Contained):
     """Manageable configuration"""
 
@@ -63,12 +65,7 @@
 @adapter_config(context=IConfigurationManager, provides=IConfiguration)
 def configuration_factory(context):
     """Configuration factory"""
-
-    def get_configuration_factory():
-        registry = get_global_registry()
-        return registry.queryAdapter(context, IConfigurationFactory, default=Configuration)
-
-    return get_annotation_adapter(context, SKIN_CONFIGURATION_KEY, factory=lambda: get_configuration_factory(),
+    return get_annotation_adapter(context, SKIN_CONFIGURATION_KEY, factory=IConfiguration,
                                   name='++configuration++')
 
 
@@ -108,6 +105,7 @@
 #
 
 @implementer(IBackOfficeConfiguration)
+@factory_config(provided=IBackOfficeConfiguration)
 class BackOfficeConfiguration(Persistent, Contained):
     """Back-office manageable configuration"""
 
@@ -130,12 +128,7 @@
 @adapter_config(context=IConfigurationManager, provides=IBackOfficeConfiguration)
 def back_office_configuration_factory(context):
     """Back-office configuration factory"""
-
-    def get_configuration_factory():
-        registry = get_global_registry()
-        return registry.queryAdapter(context, IBackOfficeConfigurationFactory, default=BackOfficeConfiguration)
-
-    return get_annotation_adapter(context, SKIN_BACK_CONFIGURATION_KEY, factory=lambda: get_configuration_factory(),
+    return get_annotation_adapter(context, SKIN_BACK_CONFIGURATION_KEY, factory=IBackOfficeConfiguration,
                                   name='++back-configuration++')