Force debugging logging for external libs and disables publisher/dataset
Force debugging logging for external libs and disables publisher/dataset

Because of the issue in #854, we've temporarily disabled the publisher and
datasets views of the site-usage data until we can resolve the issue.

--- a/ckanext/ga_report/download_analytics.py
+++ b/ckanext/ga_report/download_analytics.py
@@ -1,12 +1,17 @@
 import os
 import logging
 import datetime
+import httplib
 import collections
 from pylons import config
 from ga_model import _normalize_url
 import ga_model
 
 #from ga_client import GA
+
+import logging
+logger.setLevel(logging.DEBUG)
+
 
 log = logging.getLogger('ckanext.ga-report')
 
@@ -178,15 +183,20 @@
 
         # Supported query params at
         # https://developers.google.com/analytics/devguides/reporting/core/v3/reference
-        results = self.service.data().ga().get(
-                                 ids='ga:' + self.profile_id,
-                                 filters=query,
-                                 start_date=start_date,
-                                 metrics=metrics,
-                                 sort=sort,
-                                 dimensions="ga:pagePath",
-                                 max_results=10000,
-                                 end_date=end_date).execute()
+        try:
+            results = self.service.data().ga().get(
+                                     ids='ga:' + self.profile_id,
+                                     filters=query,
+                                     start_date=start_date,
+                                     metrics=metrics,
+                                     sort=sort,
+                                     dimensions="ga:pagePath",
+                                     max_results=10000,
+                                     end_date=end_date).execute()
+        except httplib.BadStatusLine:
+            log.error(u"Failed to download data=> ids: ga:{0}, filters: {1}, start_date: {2}, end_date: {3}, metrics: {4}, sort: {5}, dimensions: ga:pagePath".format(
+                self.profile_id, query, start_date, end_date, metrics, sort ))
+            return dict(url=[])
 
         packages = []
         log.info("There are %d results" % results['totalResults'])

--- a/ckanext/ga_report/ga_model.py
+++ b/ckanext/ga_report/ga_model.py
@@ -381,11 +381,8 @@
            order_by(model.Group.name).all()
 
 def get_children(publisher):
-    '''Finds child publishers for the given publisher (object). (Not recursive)'''
-    from ckan.model.group import HIERARCHY_CTE
-    return model.Session.query(model.Group).\
-           from_statement(HIERARCHY_CTE).params(id=publisher.id, type='publisher').\
-           all()
+    '''Finds child publishers for the given publisher (object). (Not recursive i.e. returns one level)'''
+    return publisher.get_children_groups(type='organization')
 
 def go_down_tree(publisher):
     '''Provided with a publisher object, it walks down the hierarchy and yields each publisher,

--- a/ckanext/ga_report/templates/ga_report/ga_util.html
+++ b/ckanext/ga_report/templates/ga_report/ga_util.html
@@ -62,10 +62,13 @@
   <span class="subheading">
     <img src="/images/arrow-down-right.png" />
     <a class="${if_(active_name=='Site-wide','active')}" href="${h.url_for(controller='ckanext.ga_report.controller:GaReport',action='index')}${if_(c.month,'?month='+c.month)}">Site-wide</a>
+    <!--!
+    Temporarily disabled for production whilst we get to the bottom of #854
     <span class="divider">|</span>
     <a class="${if_(active_name=='Publishers','active')}" href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='publishers')}${if_(c.month,'?month='+c.month)}">Publishers</a>
     <span class="divider">|</span>
     <a class="${if_(active_name=='Datasets','active')}" href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='read')}${if_(c.month,'?month='+c.month)}">Datasets</a>
+    -->
   </span>
 </div>
 

--- a/ckanext/ga_report/templates/ga_report/publisher/index.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/index.html
@@ -8,9 +8,9 @@
   <py:def function="page_title">Usage by Publisher</py:def>
 
 
-  <py:match path="primarysidebar">
+  <py:def path="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">
     <link rel="stylesheet" type="text/css" href="/scripts/vendor/rickshaw.min.css"/>

--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.html
@@ -19,9 +19,9 @@
     <script type="text/javascript" src="/scripts/vendor/rickshaw.min.js"></script>
   </py:def>
 
-  <py:match path="primarysidebar">
+  <py:def path="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:match>
+  </py:def>
   <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,9 +19,9 @@
     <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:match>
+  </py:def>
 
   <py:def function="page_heading">Site Usage ${usage_nav('Site-wide')}</py:def>