equal
deleted
inserted
replaced
18 # import interfaces |
18 # import interfaces |
19 from pyams_skin.interfaces.extension import \ |
19 from pyams_skin.interfaces.extension import \ |
20 IGoogleAnalyticsInfo, GOOGLE_ANALYTICS_INFO_KEY, \ |
20 IGoogleAnalyticsInfo, GOOGLE_ANALYTICS_INFO_KEY, \ |
21 IUserReportInfo, USER_REPORT_INFO_KEY, IGoogleTagManagerInfo, GOOGLE_TAGS_INFO_KEY |
21 IUserReportInfo, USER_REPORT_INFO_KEY, IGoogleTagManagerInfo, GOOGLE_TAGS_INFO_KEY |
22 from pyams_utils.interfaces.site import ISiteRoot |
22 from pyams_utils.interfaces.site import ISiteRoot |
23 from zope.annotation.interfaces import IAnnotations |
|
24 |
23 |
25 # import packages |
24 # import packages |
26 from persistent import Persistent |
25 from persistent import Persistent |
27 from pyams_utils.adapter import adapter_config |
26 from pyams_utils.adapter import adapter_config, get_annotation_adapter |
28 from zope.interface import implementer |
27 from zope.interface import implementer |
29 from zope.schema.fieldproperty import FieldProperty |
28 from zope.schema.fieldproperty import FieldProperty |
30 |
29 |
31 |
30 |
32 @implementer(IGoogleTagManagerInfo) |
31 @implementer(IGoogleTagManagerInfo) |
39 |
38 |
40 |
39 |
41 @adapter_config(context=ISiteRoot, provides=IGoogleTagManagerInfo) |
40 @adapter_config(context=ISiteRoot, provides=IGoogleTagManagerInfo) |
42 def google_tag_manager_info_factory(context): |
41 def google_tag_manager_info_factory(context): |
43 """Google Tag Manager settings factory""" |
42 """Google Tag Manager settings factory""" |
44 annotations = IAnnotations(context) |
43 return get_annotation_adapter(context, GOOGLE_TAGS_INFO_KEY, GoogleTagManagerInfo, |
45 info = annotations.get(GOOGLE_TAGS_INFO_KEY) |
44 notify=False, locate=False) |
46 if info is None: |
|
47 info = annotations[GOOGLE_TAGS_INFO_KEY] = GoogleTagManagerInfo() |
|
48 return info |
|
49 |
45 |
50 |
46 |
51 @implementer(IGoogleAnalyticsInfo) |
47 @implementer(IGoogleAnalyticsInfo) |
52 class GoogleAnalyticsInfo(Persistent): |
48 class GoogleAnalyticsInfo(Persistent): |
53 """Google Analytics settings class""" |
49 """Google Analytics settings class""" |
59 |
55 |
60 |
56 |
61 @adapter_config(context=ISiteRoot, provides=IGoogleAnalyticsInfo) |
57 @adapter_config(context=ISiteRoot, provides=IGoogleAnalyticsInfo) |
62 def google_analytics_info_factory(context): |
58 def google_analytics_info_factory(context): |
63 """Google Analytics settings factory""" |
59 """Google Analytics settings factory""" |
64 annotations = IAnnotations(context) |
60 return get_annotation_adapter(context, GOOGLE_ANALYTICS_INFO_KEY, GoogleAnalyticsInfo, |
65 info = annotations.get(GOOGLE_ANALYTICS_INFO_KEY) |
61 notify=False, locate=False) |
66 if info is None: |
|
67 info = annotations[GOOGLE_ANALYTICS_INFO_KEY] = GoogleAnalyticsInfo() |
|
68 return info |
|
69 |
62 |
70 |
63 |
71 @implementer(IUserReportInfo) |
64 @implementer(IUserReportInfo) |
72 class UserReportInfo(Persistent): |
65 class UserReportInfo(Persistent): |
73 """User report settings class""" |
66 """User report settings class""" |
78 |
71 |
79 |
72 |
80 @adapter_config(context=ISiteRoot, provides=IUserReportInfo) |
73 @adapter_config(context=ISiteRoot, provides=IUserReportInfo) |
81 def user_report_info_factory(context): |
74 def user_report_info_factory(context): |
82 """User report settings factory""" |
75 """User report settings factory""" |
83 annotations = IAnnotations(context) |
76 return get_annotation_adapter(context, USER_REPORT_INFO_KEY, UserReportInfo, |
84 info = annotations.get(USER_REPORT_INFO_KEY) |
77 notify=False, locate=False) |
85 if info is None: |
|
86 info = annotations[USER_REPORT_INFO_KEY] = UserReportInfo() |
|
87 return info |
|