Declare "forms" and "views" content factories
authorThierry Florac <thierry.florac@onf.fr>
Tue, 16 May 2017 11:01:09 +0200
changeset 76 e3c1ec4f3260
parent 75 06d6babc5fd7
child 77 a6c8b6a420f7
Declare "forms" and "views" content factories
src/pyams_content/generations/__init__.py
--- a/src/pyams_content/generations/__init__.py	Tue May 16 11:00:11 2017 +0200
+++ b/src/pyams_content/generations/__init__.py	Tue May 16 11:01:09 2017 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_content.shared.imagemap.manager import ImageMapsManager
 
 __docformat__ = 'restructuredtext'
 
@@ -34,7 +33,10 @@
 from pyams_catalog.nltk import NltkFullTextProcessor
 from pyams_catalog.site import check_required_indexes
 from pyams_content.shared.common.manager import SharedToolContainer
+from pyams_content.shared.form.manager import FormsManager
+from pyams_content.shared.imagemap.manager import ImageMapsManager
 from pyams_content.shared.news.manager import NewsManager
+from pyams_content.shared.view.manager import ViewsManager
 from pyams_i18n.index import I18nTextIndexWithInterface
 from pyams_security.index import PrincipalsRoleIndex
 from pyams_utils.registry import utility_config
@@ -126,6 +128,20 @@
             tools_configuration.tools_name = tools_name
         else:
             tools_manager = site[tools_name]
+        # check views shared tool
+        factory = registry.settings.get('pyams_content.config.views_tool_factory')
+        if (factory is None) or (factory.upper() not in ('NONE', '--')):
+            views_tool_name = tools_configuration.views_tool_name or \
+                              registry.settings.get('pyams_content.config.views_tool_name', 'views')
+            if views_tool_name not in tools_manager:
+                if factory is not None:
+                    factory = DottedNameResolver().resolve(factory)
+                else:
+                    factory = ViewsManager
+                tool = factory()
+                registry.notify(ObjectCreatedEvent(tool))
+                tools_manager[views_tool_name] = tool
+                tools_configuration.views_tool_name = views_tool_name
         # check news shared tool
         factory = registry.settings.get('pyams_content.config.news_tool_factory')
         if (factory is None) or (factory.upper() not in ('NONE', '--')):
@@ -154,3 +170,17 @@
                 registry.notify(ObjectCreatedEvent(tool))
                 tools_manager[maps_tool_name] = tool
                 tools_configuration.imagemaps_tool_name = maps_tool_name
+        # check forms shared tool
+        factory = registry.settings.get('pyams_content.config.forms_tool_factory')
+        if (factory is None) or (factory.upper() not in ('NONE', '--')):
+            forms_tool_name = tools_configuration.forms_tool_name or \
+                              registry.settings.get('pyams_content.config.forms_tool_name', 'forms')
+            if forms_tool_name not in tools_manager:
+                if factory is not None:
+                    factory = DottedNameResolver().resolve(factory)
+                else:
+                    factory = FormsManager
+                tool = factory()
+                registry.notify(ObjectCreatedEvent(tool))
+                tools_manager[forms_tool_name] = tool
+                tools_configuration.forms_tool_name = forms_tool_name