html fixes and reeneable downloads count
--- a/ckanext/ga_report/download_analytics.py
+++ b/ckanext/ga_report/download_analytics.py
@@ -2,11 +2,9 @@
import logging
import datetime
import httplib
-import urllib
import collections
import requests
import json
-import re
from pylons import config
from ga_model import _normalize_url
import ga_model
@@ -426,7 +424,7 @@
args["end-date"] = end_date
args["ids"] = "ga:" + self.profile_id
- args["filters"] = 'ga:eventAction==Download'
+ args["filters"] = 'ga:eventAction==download'
args["dimensions"] = "ga:eventLabel"
args["metrics"] = "ga:totalEvents"
args["alt"] = "json"
@@ -452,7 +450,7 @@
if progress_count % 100 == 0:
log.debug('.. %d/%d done so far', progress_count, progress_total)
- url = urllib.unquote(result[0].strip())
+ url = result[0].strip()
# Get package id associated with the resource that has this URL.
q = model.Session.query(model.Resource)
@@ -460,15 +458,8 @@
r = q.filter(model.Resource.cache_url.like("%s%%" % url)).first()
else:
r = q.filter(model.Resource.url.like("%s%%" % url)).first()
-
- # new style internal download links
- if re.search('(?:/resource/)(.*)(?:/download/)',url):
- resource_id = re.search('(?:/resource/)(.*)(?:/download/)',url)
- r = q.filter(model.Resource.id.like("%s%%" % resource_id.group(1))).first()
package_name = r.resource_group.package.name if r else ""
-
-
if package_name:
data[package_name] = data.get(package_name, 0) + int(result[1])
else:
@@ -481,7 +472,7 @@
log.info('Associating downloads of resource URLs with their respective datasets')
process_result_data(results.get('rows'))
- '''try:
+ try:
# Because of issues of invalid responses, we are going to make these requests
# ourselves.
headers = {'authorization': 'Bearer ' + self.token}
@@ -501,7 +492,7 @@
results = dict(url=[])
log.info('Associating downloads of cache resource URLs with their respective datasets')
- process_result_data(results.get('rows'), cached=False)'''
+ process_result_data(results.get('rows'), cached=False)
self._filter_out_long_tail(data, MIN_DOWNLOADS)
ga_model.update_sitewide_stats(period_name, "Downloads", data, period_complete_day)
--- a/ckanext/ga_report/plugin.py
+++ b/ckanext/ga_report/plugin.py
@@ -67,17 +67,17 @@
action='publisher_csv'
)
map.connect(
- '/site-usagesetsets_{id}_{month}.csv',
+ '/site-usage/dataset/datasets_{id}_{month}.csv',
controller='ckanext.ga_report.controller:GaDatasetReport',
action='dataset_csv'
)
map.connect(
- '/site-usageset',
+ '/site-usage/dataset',
controller='ckanext.ga_report.controller:GaDatasetReport',
action='read'
)
map.connect(
- '/site-usageset/{id}',
+ '/site-usage/dataset/{id}',
controller='ckanext.ga_report.controller:GaDatasetReport',
action='read_publisher'
)
--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.html
@@ -85,7 +85,7 @@
${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))}
</td>
<td class="td-numeric">${views}</td>
- <td class="td-numeric">${downloads}</td>
+ <td class="td-numeric">${downloads}</td>
</tr>
</py:for>
</table>
--- a/ckanext/ga_report/templates/ga_report/site/index.html
+++ b/ckanext/ga_report/templates/ga_report/site/index.html
@@ -29,7 +29,7 @@
<div class="panel-body">
<ul>
<li><a href="/site-usage/publisher">Publisher Usage Statistics</a></li>
- <li><a href="/site-usageset">Dataset Usage Statistics</a></li>
+ <li><a href="/site-usage/dataset">Dataset Usage Statistics</a></li>
</ul>
</div>
</div>
--- a/ckanext/ga_report/templates/ga_report/site/layout_base.html
+++ b/ckanext/ga_report/templates/ga_report/site/layout_base.html
@@ -114,7 +114,7 @@
</span>
</div>
<a href="${h.url('home')}">
- <img width="64" src="${h.url_for_static(g.site_logo)}" alt="${g.site_title} Logo" title="${g.site_title} Logo" id="logo" />
+ <img width="196" src="${h.url_for_static(g.site_logo)}" alt="${g.site_title} Logo" title="${g.site_title} Logo" id="logo" />
</a>
<div id="site-name">
<!-- <a href="${h.url('home')}">${g.site_title} — ${g.site_description}</a>-->