[403] Fix rickshaw choking if there is an empty 'Others' series.
[403] Fix rickshaw choking if there is an empty 'Others' series.

--- a/ckanext/ga_report/controller.py
+++ b/ckanext/ga_report/controller.py
@@ -218,7 +218,10 @@
                     'x':_get_unix_epoch(stat.period_name),
                     'y':float(stat.value)
                     })
-            graph = [ graph_dict[x[0]] for x in entries ]
+            stats_in_table = [x[0] for x in entries]
+            stats_not_in_table = set(graph_dict.keys()) - set(stats_in_table)
+            stats = stats_in_table + sorted(list(stats_not_in_table))
+            graph = [graph_dict[x] for x in stats]
             setattr(c, v+'_graph', json.dumps( _to_rickshaw(graph,percentageMode=True) ))
 
             # Get the total for each set of values and then set the value as
@@ -445,12 +448,13 @@
                 fraction = float(point['y']) / totals[point['x']]
                 if not (series in data) and fraction>THRESHOLD:
                     data.append(series)
-        # Overwrite data with a set of intereting series
+        # Overwrite data with a set of interesting series
         others = [ x for x in raw_data if not (x in data) ]
-        data.append({ 
-            'name':'Other',
-            'data': [ {'x':x,'y':y} for x,y in get_totals(others).items() ] 
-            })
+        if len(others):
+            data.append({ 
+                'name':'Other',
+                'data': [ {'x':x,'y':y} for x,y in get_totals(others).items() ] 
+                })
         # Turn each point into a percentage
         for series in data:
             for point in series['data']:

--- a/ckanext/ga_report/helpers.py
+++ b/ckanext/ga_report/helpers.py
@@ -80,7 +80,7 @@
     return base.render_snippet('ga_report/ga_popular_single.html', **context)
 
 
-def most_popular_datasets(publisher, count=20):
+def most_popular_datasets(publisher, count=20, preview_image=None):
 
     if not publisher:
         _log.error("No valid publisher passed to 'most_popular_datasets'")
@@ -92,7 +92,8 @@
         'dataset_count': len(results),
         'datasets': results,
 
-        'publisher': publisher
+        'publisher': publisher,
+        'preview_image': preview_image
     }
 
     return base.render_snippet('ga_report/publisher/popular.html', **ctx)

--- a/ckanext/ga_report/templates/ga_report/ga_util.html
+++ b/ckanext/ga_report/templates/ga_report/ga_util.html
@@ -70,6 +70,32 @@
   </span>
 </div>
 
+<div py:def="ga_sidebar(download_link)">
+  <div class="boxed">
+    <div class="widget-container widget_text">
+      <h4>Download</h4>
+      <p><center>
+        <a class="btn button btn-primary" href="${download_link}">Download as CSV</a></center>
+      </p>
+    </div>
+    <div class="widget-container widget_text">
+      <h4>Graph Legend</h4>
+      <div id="graph-legend-container">
+        <div style="display: none;" id="legend_none">(No graph is loaded)</div>
+      </div>
+    </div>
+    <div class="widget-container widget_text">
+      <h4>Notes</h4>
+      <ul>
+          <li>"Views" is the number of times a page was loaded in users' browsers.</li>
+          <li>"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.</li>
+          <li>These usage statistics are confined to users with javascript enabled, which excludes web crawlers and API calls.</li>
+          <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>
+
 
 </html>
 

--- a/ckanext/ga_report/templates/ga_report/notes.html
+++ /dev/null
@@ -1,16 +1,1 @@
-<html xmlns:py="http://genshi.edgewall.org/"
-  xmlns:i18n="http://genshi.edgewall.org/i18n"
-  xmlns:xi="http://www.w3.org/2001/XInclude"
-  py:strip="">
 
-    <li class="widget-container boxed widget_text">
-      <h4>Notes</h4>
-      <ul>
-          <li>"Views" is the number of times a page was loaded in users' browsers.</li>
-          <li>"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.</li>
-          <li>These usage statistics are confined to users with javascript enabled, which excludes web crawlers and API calls.</li>
-          <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>
-    </li>
-</html>
-

--- a/ckanext/ga_report/templates/ga_report/publisher/index.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/index.html
@@ -7,21 +7,9 @@
 
   <py:def function="page_title">Usage by Publisher</py:def>
 
-  <py:def function="content_class"><!----></py:def>
 
   <py:match path="primarysidebar">
-    <li class="widget-container boxed widget_text">
-      <h4>Download</h4>
-      <p><center>
-          <a class="btn button btn-primary" href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='publisher_csv',month=c.month or 'all')}">Download as CSV</a></center>
-      </p>
-    </li>
-    <li class="widget-container boxed widget_text">
-      <h4>Graph Legend</h4>
-      <div id="graph-legend-container">
-      </div>
-    </li>
-    <xi:include href="../notes.html" />
+    ${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 function="optional_head">

--- a/ckanext/ga_report/templates/ga_report/publisher/popular.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/popular.html
@@ -15,7 +15,12 @@
                 </li>
             </py:for>
         </ul>
-      <p class="">${h.link_to("More usage data for " + publisher.title, h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='read_publisher',id=publisher.name))}</p>
+      <p>
+        <a href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='read_publisher',id=publisher.name)}">
+          <img py:if="preview_image" src="${preview_image}" /><br/>
+          More usage data for ${publisher.title}
+        </a>
+      </p>
      </div>
   </py:if>
 </html>

--- a/ckanext/ga_report/templates/ga_report/publisher/read.html
+++ b/ckanext/ga_report/templates/ga_report/publisher/read.html
@@ -6,8 +6,6 @@
   <xi:include href="../ga_util.html" />
 
   <py:def function="page_title">Usage by Dataset</py:def>
-
-  <py:def function="content_class"><!----></py:def>
 
   <py:def function="optional_head">
     <link rel="stylesheet" type="text/css" href="/scripts/vendor/rickshaw.min.css"/>
@@ -21,18 +19,7 @@
   </py:def>
 
   <py:match path="primarysidebar">
-    <li class="widget-container boxed widget_text">
-      <h4>Download</h4>
-      <p><center>
-          <a class="btn button btn-primary" href="${h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport',action='dataset_csv',id=c.publisher_name or 'all',month=c.month or 'all')}">Download as CSV</a></center>
-      </p>
-    </li>
-    <li class="widget-container boxed widget_text">
-      <h4>Graph Legend</h4>
-      <div id="graph-legend-container">
-      </div>
-    </li>
-    <xi:include href="../notes.html" />
+    ${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>
 
 

--- a/ckanext/ga_report/templates/ga_report/site/downloads.html
+++ b/ckanext/ga_report/templates/ga_report/site/downloads.html
@@ -7,17 +7,8 @@
 
   <py:def function="page_title">Downloads</py:def>
 
-  <py:def function="content_class"><!----></py:def>
-
   <py:match path="primarysidebar">
-    <li py:if="c.downloads" class="widget-container boxed widget_text">
-      <h4>Download</h4>
-      <p><center>
-          <a class="btn button btn-primary" href="${h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv_downloads',month=c.month or 'all')}">Download as CSV</a></center>
-      </p>
-    </li>
-    <xi:include href="../notes.html" />
-
+    ${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv_downloads',month=c.month or 'all'))}
   </py:match>
 
   <div py:match="content">

--- a/ckanext/ga_report/templates/ga_report/site/index.html
+++ b/ckanext/ga_report/templates/ga_report/site/index.html
@@ -6,8 +6,6 @@
   <xi:include href="../ga_util.html" />
 
   <py:def function="page_title">Site usage</py:def>
-
-  <py:def function="content_class"><!----></py:def>
 
   <py:def function="optional_head">
     <link rel="stylesheet" type="text/css" href="/scripts/vendor/rickshaw.min.css"/>
@@ -21,20 +19,7 @@
   </py:def>
 
   <py:match path="primarysidebar">
-    <li class="widget-container boxed widget_text">
-      <h4>Download</h4>
-      <p><center>
-          <a class="btn button btn-primary" href="${h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv',month=c.month or 'all')}">Download as CSV</a></center>
-      </p>
-    </li>
-    <li class="widget-container boxed widget_text">
-      <h4>Graph Legend</h4>
-      <div id="graph-legend-container">
-        <div id="legend_none">(No graph loaded)</div>
-      </div>
-    </li>
-    <xi:include href="../notes.html" />
-
+    ${ga_sidebar(download_link=h.url_for(controller='ckanext.ga_report.controller:GaReport',action='csv',month=c.month or 'all'))}
   </py:match>
 
   <div py:match="content">