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 |
|
|
from ckanext.ga_report.helpers import (most_popular_datasets, |
from ckanext.ga_report.helpers import (most_popular_datasets, |
popular_datasets, |
popular_datasets, |
single_popular_dataset) |
single_popular_dataset) |
|
|
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) |
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): |
def get_helpers(self): |
""" |
""" |
A dictionary of extra helpers that will be available to provide |
A dictionary of extra helpers that will be available to provide |
ga report info to templates. |
ga report info to templates. |
""" |
""" |
return { |
return { |
'ga_report_installed': lambda: True, |
'ga_report_installed': lambda: True, |
'popular_datasets': popular_datasets, |
'popular_datasets': popular_datasets, |
'most_popular_datasets': most_popular_datasets, |
'most_popular_datasets': most_popular_datasets, |
'single_popular_dataset': single_popular_dataset |
'single_popular_dataset': single_popular_dataset |
} |
} |
|
|
def after_map(self, map): |
def after_map(self, map): |
map.connect( |
# GaReport |
'/data/site-usage/publisher', |
|
controller='ckanext.ga_report.controller:GaPublisherReport', |
|
action='index' |
|
) |
|
map.connect( |
|
'/data/site-usage/publisher_{month}.csv', |
|
controller='ckanext.ga_report.controller:GaPublisherReport', |
|
action='csv' |
|
) |
|
map.connect( |
|
'/data/site-usage/publisher/{id}_{month}.csv', |
|
controller='ckanext.ga_report.controller:GaPublisherReport', |
|
action='publisher_csv' |
|
) |
|
map.connect( |
|
'/data/site-usage/publisher/{id}', |
|
controller='ckanext.ga_report.controller:GaPublisherReport', |
|
action='read' |
|
) |
|
map.connect( |
map.connect( |
'/data/site-usage', |
'/data/site-usage', |
controller='ckanext.ga_report.controller:GaReport', |
controller='ckanext.ga_report.controller:GaReport', |
action='index' |
action='index' |
) |
) |
map.connect( |
map.connect( |
'/data/site-usage/data_{month}.csv', |
'/data/site-usage/data_{month}.csv', |
controller='ckanext.ga_report.controller:GaReport', |
controller='ckanext.ga_report.controller:GaReport', |
action='csv' |
action='csv' |
) |
) |
|
map.connect( |
|
'/data/site-usage/downloads', |
|
controller='ckanext.ga_report.controller:GaReport', |
|
action='downloads' |
|
) |
|
map.connect( |
|
'/data/site-usage/downloads_{month}.csv', |
|
controller='ckanext.ga_report.controller:GaReport', |
|
action='csv_downloads' |
|
) |
|
|
|
# GaDatasetReport |
|
map.connect( |
|
'/data/site-usage/publisher', |
|
controller='ckanext.ga_report.controller:GaDatasetReport', |
|
action='publishers' |
|
) |
|
map.connect( |
|
'/data/site-usage/publishers_{month}.csv', |
|
controller='ckanext.ga_report.controller:GaDatasetReport', |
|
action='publisher_csv' |
|
) |
|
map.connect( |
|
'/data/site-usage/dataset/datasets_{id}_{month}.csv', |
|
controller='ckanext.ga_report.controller:GaDatasetReport', |
|
action='dataset_csv' |
|
) |
|
map.connect( |
|
'/data/site-usage/dataset', |
|
controller='ckanext.ga_report.controller:GaDatasetReport', |
|
action='read' |
|
) |
|
map.connect( |
|
'/data/site-usage/dataset/{id}', |
|
controller='ckanext.ga_report.controller:GaDatasetReport', |
|
action='read_publisher' |
|
) |
return map |
return map |
|
|
|
|