| import logging | import logging |
| import ckan.lib.helpers as h | import ckan.lib.helpers as h |
| import ckan.plugins as p | import ckan.plugins as p |
| from ckan.plugins import implements, toolkit | from ckan.plugins import implements, toolkit |
| #import gasnippet | |
| #import commands | |
| #import dbutil | |
| log = logging.getLogger('ckanext.ga-report') | log = logging.getLogger('ckanext.ga-report') |
| class GAReportPlugin(p.SingletonPlugin): | class GAReportPlugin(p.SingletonPlugin): |
| implements(p.IConfigurer, inherit=True) | implements(p.IConfigurer, inherit=True) |
| implements(p.IRoutes, inherit=True) | implements(p.IRoutes, inherit=True) |
| implements(p.ITemplateHelpers, inherit=True) | |
| def update_config(self, config): | def update_config(self, config): |
| toolkit.add_template_directory(config, 'templates') | toolkit.add_template_directory(config, 'templates') |
| toolkit.add_public_directory(config, 'public') | toolkit.add_public_directory(config, 'public') |
| def get_helpers(self): | |
| """ | |
| A dictionary of extra helpers that will be available to provide | |
| ga report info to templates. | |
| """ | |
| from ckanext.ga_report.helpers import most_popular_datasets | |
| return { | |
| 'ga_report_installed': lambda: True, | |
| 'most_popular_datasets': most_popular_datasets, | |
| } | |
| def after_map(self, map): | def after_map(self, map): |
| map.connect( | map.connect( |
| '/data/analytics', | '/data/analytics/publisher', |
| controller='ckanext.ga_report.controller:GaReport', | |
| action='index' | |
| ) | |
| map.connect( | |
| '/data/analytics_{month}.csv', | |
| controller='ckanext.ga_report.controller:GaReport', | |
| action='csv' | |
| ) | |
| map.connect( | |
| '/data/analytics/publisher/', | |
| controller='ckanext.ga_report.controller:GaPublisherReport', | controller='ckanext.ga_report.controller:GaPublisherReport', |
| action='index' | action='index' |
| ) | ) |
| map.connect( | map.connect( |
| '/data/analytics/publisher/{id}', | '/data/analytics/publisher/{id}', |
| controller='ckanext.ga_report.controller:GaPublisherReport', | controller='ckanext.ga_report.controller:GaPublisherReport', |
| action='read' | action='read' |
| ) | ) |
| map.connect( | |
| '/data/analytics', | |
| controller='ckanext.ga_report.controller:GaReport', | |
| action='index' | |
| ) | |
| map.connect( | |
| '/data/analytics/data_{month}.csv', | |
| controller='ckanext.ga_report.controller:GaReport', | |
| action='csv' | |
| ) | |
| return map | return map |