Merge remote-tracking branch 'origin/777-responsive'
--- a/ckanext/ga_report/download_analytics.py
+++ b/ckanext/ga_report/download_analytics.py
@@ -193,10 +193,6 @@
# Supported query params at
# https://developers.google.com/analytics/devguides/reporting/core/v3/reference
try:
- # Because of issues of invalid responses, we are going to make these requests
- # ourselves.
- headers = {'authorization': 'Bearer ' + self.token}
-
args = {}
args["sort"] = "-ga:pageviews"
args["max-results"] = 100000
@@ -208,16 +204,11 @@
args["filters"] = query
args["alt"] = "json"
- r = requests.get("https://www.googleapis.com/analytics/v3/data/ga", params=args, headers=headers)
- if r.status_code != 200:
- raise Exception("Request with params: %s failed" % args)
-
- results = json.loads(r.content)
- print len(results.keys())
- except Exception, e:
- log.exception(e)
- #return dict(url=[])
- raise e
+ results = self._get_json(args)
+
+ except Exception, e:
+ log.exception(e)
+ return dict(url=[])
packages = []
log.info("There are %d results" % results['totalResults'])
@@ -264,8 +255,9 @@
'Google Analytics token file under key: googleanalytics.token.filepath'
return
- try:
- log.info("Trying to refresh our OAuth token")
+ log.info("Trying to refresh our OAuth token")
+ try:
+ from ga_auth import init_service
self.token, svc = init_service(ga_token_filepath, None)
log.info("OAuth token refreshed")
except Exception, auth_exception:
@@ -277,9 +269,9 @@
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:
--- a/ckanext/ga_report/templates/ga_report/ga_util.html
+++ b/ckanext/ga_report/templates/ga_report/ga_util.html
@@ -70,7 +70,6 @@
</div>
<div py:def="ga_sidebar(download_link)">
- <div class="boxed">
<div class="widget-container widget_text">
<h4>Download</h4>
<p><center>
@@ -92,7 +91,7 @@
<li>The results are not shown when the number of views/visits is tiny. Where these relate to site pages, results are available in full in the CSV download. Where these relate to users' web browser information, results are not disclosed, for privacy reasons.</li>
</ul>
</div>
- </div>
+
</div>
--- 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,9 +24,23 @@
<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/site-usage">Site Analytics</a></li>
+ <li><a href="/data/site-usage/publisher">Publishers</a></li>
+ </py:match>
+
+
<div py:match="content">
+
+ <h3 style='text-align:center;'>
+ <a href="/data/site-usage">Site-wide</a>
+ <span style="color: #bbb;margin:10px;">|</span>
+ Publishers
+ <span style="color: #bbb;margin:10px;">|</span>
+ <a href="/data/site-usage/dataset">Datasets</a>
+ </h3>
<div class="boxed">
--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.html
@@ -19,12 +19,27 @@
<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/site-usage">Site Analytics</a></li>
+ <li><a href="/data/site-usage/publisher">Datasets</a></li>
+ <li py:if="c.publisher"><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">
+ <h3 style='text-align:center;'>
+ <a href="/data/site-usage">Site-wide</a>
+ <span style="color: #bbb;margin:10px;">|</span>
+ <a href="/data/site-usage/publisher">Publishers</a>
+ <span style="color: #bbb;margin:10px;">|</span>
+ Datasets
+ </h3>
+
<div class="boxed">
<h3 py:if="c.publisher"><a href="${h.url_for(controller='ckanext.dgu.controllers.publisher:PublisherController',action='read',id=c.publisher.name)}">${c.publisher.title}</a></h3>
--- 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,13 +19,26 @@
<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/site-usage">Site Analytics</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">
+
+ <h3 style='text-align:center;'>
+ Site-wide
+ <span style="color: #bbb;margin:10px;">|</span>
+ <a href="/data/site-usage/publisher">Publishers</a>
+ <span style="color: #bbb;margin:10px;">|</span>
+ <a href="/data/site-usage/dataset">Datasets</a>
+ </h3>
<div class="boxed">
<div class="tabbable">