Just adding breadcrumbs
--- a/ckanext/ga_report/download_analytics.py
+++ b/ckanext/ga_report/download_analytics.py
@@ -258,31 +258,37 @@
return data
def _get_json(self, params, prev_fail=False):
- ga_token_filepath = os.path.expanduser(config.get('googleanalytics.token.filepath', ''))
- if not ga_token_filepath:
- print 'ERROR: In the CKAN config you need to specify the filepath of the ' \
- 'Google Analytics token file under key: googleanalytics.token.filepath'
- return
-
- log.info("Trying to refresh our OAuth token")
- try:
- self.token, svc = init_service(ga_token_filepath, None)
- log.info("OAuth token refreshed")
- except Exception, auth_exception:
- log.error("Oauth refresh failed")
- log.exception(auth_exception)
- return
-
- try:
+ if prev_fail:
+ import os
+ ga_token_filepath = os.path.expanduser(config.get('googleanalytics.token.filepath', ''))
+ if not ga_token_filepath:
+ print 'ERROR: In the CKAN config you need to specify the filepath of the ' \
+ 'Google Analytics token file under key: googleanalytics.token.filepath'
+ return
+
+ try:
+ self.token, svc = init_service(ga_token_filepath, None)
+ except TypeError:
+ print ('Have you correctly run the getauthtoken task and '
+ 'specified the correct token file in the CKAN config under '
+ '"googleanalytics.token.filepath"?')
+
+ try:
+ # Because of issues of invalid responses, we are going to make these requests
+ # ourselves.
headers = {'authorization': 'Bearer ' + self.token}
r = requests.get("https://www.googleapis.com/analytics/v3/data/ga", params=params, headers=headers)
if r.status_code != 200:
- log.info("STATUS: %s" % (r.status_code,))
- log.info("CONTENT: %s" % (r.content,))
- raise Exception("Request with params: %s failed" % params)
+ log.info("STATUS: %s" % (r.status_code,))
+ log.info("CONTENT: %s" % (r.content,))
+ raise Exception("Request with params: %s failed" % params)
return json.loads(r.content)
except Exception, e:
+ if not prev_fail:
+ print e
+ results = self._get_json(self, params, prev_fail=True)
+ else:
log.exception(e)
return dict(url=[])
--- a/ckanext/ga_report/templates/ga_report/publisher/index.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/index.html
@@ -8,10 +8,9 @@
<py:def function="page_title">Usage by Publisher</py:def>
-
- <py:match path="primarysidebar">
+ <py:def function="sidebar">
${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='publisher_csv',month=c.month or 'all'))}
- </py:match>
+ </py:def>
<py:def function="optional_head">
@@ -25,7 +24,14 @@
<script type="text/javascript" src="/scripts/vendor/d3.layout.min.js"></script>
<script type="text/javascript" src="/scripts/vendor/rickshaw.min.js"></script>
</py:def>
- <py:def function="page_heading">Site Usage ${usage_nav('Publishers')}</py:def>
+
+ <py:match path="breadcrumbs">
+ <li><a href="/data/search">Datasets</a></li>
+ <li><a href="/data/site-usage">Site-usage</a></li>
+ <li><a href="/data/site-usage/publisher">Publishers</a></li>
+ </py:match>
+
+
<div py:match="content">
--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.html
@@ -19,10 +19,18 @@
<script type="text/javascript" src="/scripts/vendor/rickshaw.min.js"></script>
</py:def>
- <py:match path="primarysidebar">
+ <py:def function="sidebar">
${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='dataset_csv',id=c.publisher_name or 'all',month=c.month or 'all'))}
+ </py:def>
+
+ <py:match path="breadcrumbs">
+ <li><a href="/data/search">Datasets</a></li>
+ <li><a href="/data/site-usage">Site-usage</a></li>
+ <li><a href="/data/site-usage/publisher">Publishers</a></li>
+ <li><a href="/data/site-usage/publisher/${c.publisher.name}">${c.publisher.title}</a></li>
</py:match>
- <py:def function="page_heading">Site Usage ${usage_nav('Datasets')}</py:def>
+
+
<div py:match="content">
--- a/ckanext/ga_report/templates/ga_report/site/downloads.html
+++ b/ckanext/ga_report/templates/ga_report/site/downloads.html
@@ -7,9 +7,9 @@
<py:def function="page_title">Downloads</py:def>
- <py:match path="primarysidebar">
+ <py:def path="sidebar">
${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv_downloads',month=c.month or 'all'))}
- </py:match>
+ </py:def>
<py:def function="page_heading">Downloads ${usage_nav('Downloads')}</py:def>
<div py:match="content">
--- a/ckanext/ga_report/templates/ga_report/site/index.html
+++ b/ckanext/ga_report/templates/ga_report/site/index.html
@@ -19,11 +19,17 @@
<script type="text/javascript" src="/scripts/vendor/rickshaw.min.js"></script>
</py:def>
- <py:match path="primarysidebar">
+ <py:def function="sidebar">
${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv',month=c.month or 'all'))}
+ </py:def>
+
+
+ <py:match path="breadcrumbs">
+ <li><a href="/data/search">Datasets</a></li>
+ <li><a href="/data/site-usage">Site-usage</a></li>
+ <li><a href="/data/site-usage">Site-wide</a></li>
</py:match>
- <py:def function="page_heading">Site Usage ${usage_nav('Site-wide')}</py:def>
<div py:match="content">