src/pyams_skin/extension.py
changeset 145 c7ec73c1d8be
child 240 007e0e70ef13
equal deleted inserted replaced
144:3198f3bcf67d 145:c7ec73c1d8be
       
     1 #
       
     2 # Copyright (c) 2008-2016 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyams_skin.interfaces.extension import \
       
    20     IGoogleAnalyticsInfo, GOOGLE_ANALYTICS_INFO_KEY, \
       
    21     IUserReportInfo, USER_REPORT_INFO_KEY
       
    22 from pyams_utils.interfaces.site import ISiteRoot
       
    23 from zope.annotation.interfaces import IAnnotations
       
    24 
       
    25 # import packages
       
    26 from persistent import Persistent
       
    27 from pyams_utils.adapter import adapter_config
       
    28 from zope.interface import implementer
       
    29 from zope.schema.fieldproperty import FieldProperty
       
    30 
       
    31 
       
    32 @implementer(IGoogleAnalyticsInfo)
       
    33 class GoogleAnalyticsInfo(Persistent):
       
    34     """Google Analytics settings class"""
       
    35 
       
    36     enabled = FieldProperty(IGoogleAnalyticsInfo['enabled'])
       
    37     website_id = FieldProperty(IGoogleAnalyticsInfo['website_id'])
       
    38     verification_code = FieldProperty(IGoogleAnalyticsInfo['verification_code'])
       
    39     activation_mode = FieldProperty(IGoogleAnalyticsInfo['activation_mode'])
       
    40 
       
    41 
       
    42 @adapter_config(context=ISiteRoot, provides=IGoogleAnalyticsInfo)
       
    43 def GoogleAnalyticsInfoFactory(context):
       
    44     """Google Analytics settings factory"""
       
    45     annotations = IAnnotations(context)
       
    46     info = annotations.get(GOOGLE_ANALYTICS_INFO_KEY)
       
    47     if info is None:
       
    48         info = annotations[GOOGLE_ANALYTICS_INFO_KEY] = GoogleAnalyticsInfo()
       
    49     return info
       
    50 
       
    51 
       
    52 @implementer(IUserReportInfo)
       
    53 class UserReportInfo(Persistent):
       
    54     """User report settings class"""
       
    55 
       
    56     enabled = FieldProperty(IUserReportInfo['enabled'])
       
    57     account_id = FieldProperty(IUserReportInfo['account_id'])
       
    58     activation_mode = FieldProperty(IUserReportInfo['activation_mode'])
       
    59 
       
    60 
       
    61 @adapter_config(context=ISiteRoot, provides=IUserReportInfo)
       
    62 def UserReportInfoFactory(context):
       
    63     """User report settings factory"""
       
    64     annotations = IAnnotations(context)
       
    65     info = annotations.get(USER_REPORT_INFO_KEY)
       
    66     if info is None:
       
    67         info = annotations[USER_REPORT_INFO_KEY] = UserReportInfo()
       
    68     return info