--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/theme/__init__.py Thu Oct 08 13:37:29 2015 +0200
@@ -0,0 +1,70 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.component.theme.interfaces import IThemesManagerTarget, IThemesManager, THEMES_MANAGER_KEY, IThemesInfo, \
+ IThemesTarget, THEMES_INFO_KEY
+from zope.annotation.interfaces import IAnnotations
+
+# import packages
+from persistent import Persistent
+from pyams_utils.adapter import adapter_config
+from pyramid.threadlocal import get_current_registry
+from zope.container.contained import Contained
+from zope.interface import implementer
+from zope.lifecycleevent import ObjectCreatedEvent
+from zope.location import locate
+from zope.schema.fieldproperty import FieldProperty
+
+
+@implementer(IThemesManager)
+class ThemesManager(Persistent, Contained):
+ """Themes manager persistent class"""
+
+ thesaurus_name = FieldProperty(IThemesManager['thesaurus_name'])
+ extract_name = FieldProperty(IThemesManager['extract_name'])
+
+
+@adapter_config(context=IThemesManagerTarget, provides=IThemesManager)
+def ThemesManagerFactory(target):
+ """Themes manager factory"""
+ annotations = IAnnotations(target)
+ manager = annotations.get(THEMES_MANAGER_KEY)
+ if manager is None:
+ manager = annotations[THEMES_MANAGER_KEY] = ThemesManager()
+ get_current_registry().notify(ObjectCreatedEvent(manager))
+ locate(manager, target, '++themes-manager++')
+ return manager
+
+
+@implementer(IThemesInfo)
+class ThemesInfo(Persistent, Contained):
+ """Themes info persistent class"""
+
+ themes = FieldProperty(IThemesInfo['themes'])
+
+
+@adapter_config(context=IThemesTarget, provides=IThemesInfo)
+def ThemesInfoFactory(target):
+ """Themes info factory"""
+ annotations = IAnnotations(target)
+ info = annotations.get(THEMES_INFO_KEY)
+ if info is None:
+ info = annotations[THEMES_INFO_KEY] = ThemesInfo()
+ get_current_registry().notify(ObjectCreatedEvent(info))
+ locate(info, target, '++themes++')
+ return info