10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
12 |
12 |
13 __docformat__ = 'restructuredtext' |
13 __docformat__ = 'restructuredtext' |
14 |
14 |
15 |
15 from pyams_skin.interfaces.extension import ACTIVATED_ON_BACK, ACTIVATED_ON_FRONT, IGoogleAnalyticsInfo |
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_skin.interfaces.extension import IGoogleAnalyticsInfo, ACTIVATED_ON_FRONT, ACTIVATED_ON_BACK |
|
20 from pyams_skin.interfaces.viewlet import IJSExtensionsViewletManager |
16 from pyams_skin.interfaces.viewlet import IJSExtensionsViewletManager |
21 from pyams_skin.layer import IPyAMSLayer |
17 from pyams_skin.layer import IPyAMSLayer |
|
18 from pyams_template.template import template_config |
|
19 from pyams_viewlet.viewlet import Viewlet, viewlet_config |
|
20 |
22 try: |
21 try: |
23 from pyams_zmi.layer import IAdminLayer |
22 from pyams_zmi.layer import IAdminLayer |
24 except ImportError: |
23 except ImportError: |
25 IAdminLayer = None |
24 IAdminLayer = None |
26 |
|
27 # import packages |
|
28 from pyams_template.template import template_config |
|
29 from pyams_viewlet.viewlet import viewlet_config, Viewlet |
|
30 |
25 |
31 |
26 |
32 @viewlet_config(name='analytics', manager=IJSExtensionsViewletManager) |
27 @viewlet_config(name='analytics', manager=IJSExtensionsViewletManager) |
33 @template_config(template='templates/analytics.pt', layer=IPyAMSLayer) |
28 @template_config(template='templates/analytics.pt', layer=IPyAMSLayer) |
34 class GoogleAnalyticsViewlet(Viewlet): |
29 class GoogleAnalyticsViewlet(Viewlet): |
43 return None |
38 return None |
44 else: |
39 else: |
45 if ((info.activation_mode == ACTIVATED_ON_FRONT) and IAdminLayer.providedBy(request)) or \ |
40 if ((info.activation_mode == ACTIVATED_ON_FRONT) and IAdminLayer.providedBy(request)) or \ |
46 ((info.activation_mode == ACTIVATED_ON_BACK) and not IAdminLayer.providedBy(request)): |
41 ((info.activation_mode == ACTIVATED_ON_BACK) and not IAdminLayer.providedBy(request)): |
47 return None |
42 return None |
|
43 if info.on_accepted_cookie: |
|
44 cookie_value = request.cookies.get(info.cookie_name) |
|
45 if cookie_value == info.rejected_cookie_value: |
|
46 return None |
48 return Viewlet.__new__(cls) |
47 return Viewlet.__new__(cls) |
49 |
48 |
50 @property |
49 @property |
51 def config(self): |
50 def config(self): |
52 return IGoogleAnalyticsInfo(self.request.root) |
51 return IGoogleAnalyticsInfo(self.request.root) |