src/pyams_skin/extension.py
changeset 145 c7ec73c1d8be
child 240 007e0e70ef13
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_skin/extension.py	Wed Jun 15 12:28:18 2016 +0200
@@ -0,0 +1,68 @@
+#
+# Copyright (c) 2008-2016 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_skin.interfaces.extension import \
+    IGoogleAnalyticsInfo, GOOGLE_ANALYTICS_INFO_KEY, \
+    IUserReportInfo, USER_REPORT_INFO_KEY
+from pyams_utils.interfaces.site import ISiteRoot
+from zope.annotation.interfaces import IAnnotations
+
+# import packages
+from persistent import Persistent
+from pyams_utils.adapter import adapter_config
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+
+
+@implementer(IGoogleAnalyticsInfo)
+class GoogleAnalyticsInfo(Persistent):
+    """Google Analytics settings class"""
+
+    enabled = FieldProperty(IGoogleAnalyticsInfo['enabled'])
+    website_id = FieldProperty(IGoogleAnalyticsInfo['website_id'])
+    verification_code = FieldProperty(IGoogleAnalyticsInfo['verification_code'])
+    activation_mode = FieldProperty(IGoogleAnalyticsInfo['activation_mode'])
+
+
+@adapter_config(context=ISiteRoot, provides=IGoogleAnalyticsInfo)
+def GoogleAnalyticsInfoFactory(context):
+    """Google Analytics settings factory"""
+    annotations = IAnnotations(context)
+    info = annotations.get(GOOGLE_ANALYTICS_INFO_KEY)
+    if info is None:
+        info = annotations[GOOGLE_ANALYTICS_INFO_KEY] = GoogleAnalyticsInfo()
+    return info
+
+
+@implementer(IUserReportInfo)
+class UserReportInfo(Persistent):
+    """User report settings class"""
+
+    enabled = FieldProperty(IUserReportInfo['enabled'])
+    account_id = FieldProperty(IUserReportInfo['account_id'])
+    activation_mode = FieldProperty(IUserReportInfo['activation_mode'])
+
+
+@adapter_config(context=ISiteRoot, provides=IUserReportInfo)
+def UserReportInfoFactory(context):
+    """User report settings factory"""
+    annotations = IAnnotations(context)
+    info = annotations.get(USER_REPORT_INFO_KEY)
+    if info is None:
+        info = annotations[USER_REPORT_INFO_KEY] = UserReportInfo()
+    return info