Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a surrounding div to the plone.analytics viewlet [master] #220

Merged
merged 2 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/157.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a sorrounding div to the webstats js. Fixes #157
[erral]
5 changes: 5 additions & 0 deletions plone/app/layout/analytics/tests/analytics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ Now enter some non-ascii text
>>> text = manager.render()
>>> site_settings.webstats_js in text
True

Check if the div sorrounding the script is present

>>> 'id="plone-analytics"' in text
True
8 changes: 8 additions & 0 deletions plone/app/layout/analytics/view.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div
id="plone-analytics"
tal:condition="view/webstats_js"
tal:content="structure view/webstats_js"
>
Here goes the webstats_js
</div>

10 changes: 5 additions & 5 deletions plone/app/layout/analytics/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from plone.registry.interfaces import IRegistry
from Products.CMFPlone.interfaces import ISiteSchema
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.component import getUtility
from zope.interface import implementer
from zope.viewlet.interfaces import IViewlet
Expand All @@ -10,25 +11,24 @@
@implementer(IViewlet)
class AnalyticsViewlet(BrowserView):

render = ViewPageTemplateFile('view.pt')

def __init__(self, context, request, view, manager):
super(AnalyticsViewlet, self).__init__(context, request)
self.__parent__ = view
self.context = context
self.request = request
self.view = view
self.manager = manager
self.webstats_js = ''

def update(self):
pass

def render(self):
"""render the webstats snippet"""
registry = getUtility(IRegistry)
site_settings = registry.forInterface(
ISiteSchema, prefix="plone", check=False)
try:
if site_settings.webstats_js:
return site_settings.webstats_js
self.webstats_js = site_settings.webstats_js
except AttributeError:
pass
return ''