class Renderer(base.Renderer): """Portlet renderer. This is registered in configure.zcml. The referenced page template is rendered, and the implicit variable 'view' will refer to an instance of this class. Other methods can be added and referenced in the template. """ def __init__(self, context, request, view, manager, data): self.async_loader = IAnalyticsAsyncLoader(context) super(Renderer, self).__init__(context, request, view, manager, data) @property def available(self): """ Determines whether the user has permission to see the portlet. """ mtool = getToolByName(self.context, 'portal_membership') allowed = mtool.checkPermission( 'Google Analytics: View Analytics Results', self.context) context_state = self.context.restrictedTraverse( '@@plone_context_state') return allowed and context_state.is_view_template() def getTitle(self): """ Return the title of the portlet. """ return self.data.portlet_title def getContainerId(self): """ Returns the element ID for the results container. """ return self.async_loader.getContainerId() def getJavascript(self): """ Returns a list of AnalyticsReportResults objects for the selected reports. """ analytics_tool = getToolByName(self.context, 'portal_analytics') date_range = analytics_tool.date_range return self.async_loader.getJavascript( self.data.reports, self.data.profile, date_range) render = ViewPageTemplateFile('analyticsportlet.pt')
class Renderer(base.Renderer): """Portlet renderer. This is registered in configure.zcml. The referenced page template is rendered, and the implicit variable 'view' will refer to an instance of this class. Other methods can be added and referenced in the template. """ def __init__(self, context, request, view, manager, data): self.async_loader = IAnalyticsAsyncLoader(context) super(Renderer, self).__init__(context, request, view, manager, data) @property def available(self): """ Determines whether the user has permission to see the portlet. """ mtool = getToolByName(self.context, 'portal_membership') allowed = mtool.checkPermission( 'Google Analytics: View Analytics Results', self.context) context_state = self.context.restrictedTraverse( '@@plone_context_state') return allowed and context_state.is_view_template() def getTitle(self): """ Return the title of the portlet. """ return self.data.portlet_title def getContainerId(self): """ Returns the element ID for the results container. """ return self.async_loader.getContainerId() def getJavascript(self): """ Returns a list of AnalyticsReportResults objects for the selected reports. """ return self.async_loader.getJavascript(self.data.reports, self.data.profile) render = ViewPageTemplateFile('analyticsportlet.pt')
class SiteWideAnalyticsViewlet(ViewletBase): """ A viewlet that displays the results of the reports selected in the Analytics control panel. """ render = ViewPageTemplateFile('sitewide.pt') def update(self): """ Initialize the viewlet. """ super(SiteWideAnalyticsViewlet, self).update() self.analytics_tool = getToolByName( self.context, 'portal_analytics', None) self.async_loader = IAnalyticsAsyncLoader(self.context) def available(self): """ Returns True if there are site-wide reports selected. """ profile = getattr(self.analytics_tool, 'reports_profile', None) reports = getattr(self.analytics_tool, 'reports', None) if reports and profile: return True return False def getContainerId(self): """ Returns the element ID for the results container. """ return self.async_loader.getContainerId() def getJavascript(self, date_range='month'): """ Returns a list of AnalyticsReportResults objects for the selected reports. """ profile = getattr(self.analytics_tool, 'reports_profile', None) reports = getattr(self.analytics_tool, 'reports', None) return self.async_loader.getJavascript( reports, profile, date_range=date_range)
class SiteWideAnalyticsViewlet(ViewletBase): """ A viewlet that displays the results of the reports selected in the Analytics control panel. """ render = ViewPageTemplateFile('sitewide.pt') def update(self): """ Initialize the viewlet. """ super(SiteWideAnalyticsViewlet, self).update() analytics_tool = getToolByName(self.context, 'portal_analytics', None) self.async_loader = IAnalyticsAsyncLoader(self.context) self.analytics_settings = analytics_tool.get_settings() def available(self): """ Returns True if there are site-wide reports selected. """ profile = getattr(self.analytics_settings, 'reports_profile', None) reports = getattr(self.analytics_settings, 'reports', None) if reports and profile: return True return False def getContainerId(self): """ Returns the element ID for the results container. """ return self.async_loader.getContainerId() def getJavascript(self): """ Returns a list of AnalyticsReportResults objects for the selected reports. """ profile = getattr(self.analytics_settings, 'reports_profile', None) reports = getattr(self.analytics_settings, 'reports', None) return self.async_loader.getJavascript(reports, profile)