From: Ross Jones Date: Wed, 06 Nov 2013 12:06:18 +0000 Subject: Show next to title the publisher on the /dataset page, or All datasets if no publisher X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-ga-report.git&a=commitdiff&h=49aa4d1ed461bc7fb93bfa6824b880c2cd805fd8 --- Show next to title the publisher on the /dataset page, or All datasets if no publisher --- --- 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']) @@ -258,37 +249,32 @@ return data def _get_json(self, params, prev_fail=False): - 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. + 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: + from ga_auth import init_service + 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: 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/public/css/ga_report.css +++ b/ckanext/ga_report/public/css/ga_report.css @@ -66,4 +66,7 @@ margin-top: 4px; float: left; } +.tab-content { + padding-top: 12px; +} --- a/ckanext/ga_report/public/scripts/ckanext_ga_reports.js +++ b/ckanext/ga_report/public/scripts/ckanext_ga_reports.js @@ -97,7 +97,7 @@ * Show the correct rickshaw graph in the sidebar. * Not to be called before all graphs load. */ - $('a[data-toggle="hashtab"]').on( + $('a[data-toggle="tab"]').on( 'shown', function(e) { var href = $(e.target).attr('href'); @@ -115,7 +115,7 @@ } ); /* The first tab might already have been shown */ - $('li.active > a[data-toggle="hashtab"]').trigger('shown'); + $('li.active > a[data-toggle="tab"]').trigger('shown'); }; CKAN.GA_Reports.bind_month_selector = function() { --- a/ckanext/ga_report/templates/ga_report/ga_util.html +++ b/ckanext/ga_report/templates/ga_report/ga_util.html @@ -57,42 +57,19 @@ - -
- - - Site-wide - | - Publishers - | - Datasets - -
- -
-
-

Download

-

- Download as CSV
-

-
-
-

Graph Legend

-
- -
-
-
-

Notes

+ +
+
Notes
+
    -
  • "Views" is the number of times a page was loaded in users' browsers.
  • -
  • "Downloads" is the number of times a user has clicked to download either an original or cached resource for a particular dataset. Download information is only available from 2nd December 2012; 'No data' is shown for records before that date.
  • -
  • These usage statistics are confined to users with javascript enabled, which excludes web crawlers and API calls.
  • -
  • 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.
  • +
  • "Views" is the number of times a page was loaded in users' browsers.
  • +
  • "Downloads" is the number of times a user has clicked to download either an original or cached resource for a particular dataset. Download information is only available from 2nd December 2012; 'No data' is shown for records before that date.
  • +
  • These usage statistics are confined to users with javascript enabled, which excludes web crawlers and API calls.
  • +
  • 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.
- -
+
+ --- a/ckanext/ga_report/templates/ga_report/publisher/index.html +++ b/ckanext/ga_report/templates/ga_report/publisher/index.html @@ -6,12 +6,6 @@ Usage by Publisher - - - - ${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='publisher_csv',month=c.month or 'all'))} - - @@ -30,46 +24,51 @@
  • Publishers
  • +
    + +   Download as CSV + +

    Site Usage

    - -
    - -

    - Site-wide - | - Publishers - | - Datasets -

    - - -
    - - ${rickshaw_graph(c.top_publishers_graph,'publishers')} +
    +
    +
    + Graph Legend +
    + +
    +
    +
    +
    +
    + Publishers + ${rickshaw_graph(c.top_publishers_graph,'publishers')} +
    +
    +

    -

    Statistics for

    +

    Statistics for

    ${month_selector(c.month, c.months, c.day)}
    - - - - - - - - - - - -
    PublisherDataset Views
    - ${h.link_to(publisher.title, h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport', action='read_publisher', id=publisher.name) + (("?month=" + c.month) if c.month else ''))} - ${views}
    -
    + + + + + + + + + + + +
    PublisherDataset Views
    + ${h.link_to(publisher.title, h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport', action='read_publisher', id=publisher.name) + (("?month=" + c.month) if c.month else ''))} + ${views}
    --- a/ckanext/ga_report/templates/ga_report/publisher/read.html +++ b/ckanext/ga_report/templates/ga_report/publisher/read.html @@ -19,75 +19,87 @@ - - ${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'))} -
  • Site Analytics
  • -
  • Datasets
  • -
  • ${c.publisher.title}
  • + +
  • Publishers
  • +
  • ${c.publisher.title}
  • +
    + +
  • Usage By Dataset
  • +
    +
    + +   Download as CSV + +

    Site Usage + ${c.publisher.title} + All datasets +

    -
    -

    - Site-wide - | - Publishers - | - Datasets -

    +
    +
    +
    + Graph Legend +
    + +
    +
    +
    +
    +
    + + ${rickshaw_graph(c.graph_data,'dataset-downloads',debug=True)} + +
    +
    +
    +
    + +

    Statistics for ${h.month_option_title(c.month,c.months,c.day)}:

    +
    + +

    Statistics for all months

    +
    +
    +
    + ${month_selector(c.month, c.months, c.day)} -
    -

    ${c.publisher.title}

    + + +
    + +
    No page views in this period.
    + + + + + + + + + + + + + + +
    DatasetViewsDownloads
    + ${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))} + ${views}${downloads}
    +
    - - ${rickshaw_graph(c.graph_data,'dataset-downloads',debug=True)} - -
    -
    - - ${month_selector(c.month, c.months, c.day)} - - - -
    -
    - -

    Statistics for ${h.month_option_title(c.month,c.months,c.day)}:

    -
    - -

    Statistics for all months:

    -
    -
    No page views in this period.
    - - - - - - - - - - - - - - -
    DatasetViewsDownloads
    - ${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))} - ${views}${downloads}
    -
    - -
    + ${ga_footer()}
    --- a/ckanext/ga_report/templates/ga_report/site/index.html +++ b/ckanext/ga_report/templates/ga_report/site/index.html @@ -19,159 +19,184 @@ - - ${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv',month=c.month or 'all'))} - - -
  • Site Analytics
  • Site-wide
  • -
    - -

    - Site-wide - | - Publishers - | - Datasets -

    - -
    -
    -
    -
    -
    +
    +
    +