Source code for pyams_skin.viewlet.extension.user_report

#
# 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'

from pyams_skin.interfaces.extension import ACTIVATED_ON_BACK, ACTIVATED_ON_FRONT, IUserReportInfo
from pyams_skin.interfaces.viewlet import IJSExtensionsViewletManager
from pyams_skin.layer import IPyAMSLayer
from pyams_template.template import template_config
from pyams_viewlet.viewlet import Viewlet, viewlet_config

try:
    from pyams_zmi.layer import IAdminLayer
except ImportError:
    IAdminLayer = None


[docs]@viewlet_config(name='user-report', manager=IJSExtensionsViewletManager) @template_config(template='templates/user_report.pt', layer=IPyAMSLayer) class UserReportViewlet(Viewlet): """Google Analytics viewlet""" def __new__(cls, context, request, view, manager): info = IUserReportInfo(request.root) if not info.enabled: return None if IAdminLayer is None: if info.activation_mode == ACTIVATED_ON_BACK: return None else: if ((info.activation_mode == ACTIVATED_ON_FRONT) and IAdminLayer.providedBy(request)) or \ ((info.activation_mode == ACTIVATED_ON_BACK) and not IAdminLayer.providedBy(request)): return None if info.on_accepted_cookie: cookie_value = request.cookies.get(info.cookie_name) if cookie_value == info.rejected_cookie_value: return None return Viewlet.__new__(cls) @property def config(self): return IUserReportInfo(self.request.root)