Repository: OCHA-DAP/hdx-ckan

Issue:
Add Colombia to the focus countries list drop down on the home page



Discussion:

Resolving patch:
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/count.py b/ckanext-hdx_theme/ckanext/hdx_theme/count.py
--- a/ckanext-hdx_theme/ckanext/hdx_theme/count.py
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/count.py
@@ -3,21 +3,54 @@
 from ckan.lib import base
 import sqlalchemy
 
+
 class CountController(base.BaseController):
 
-    def _get_count(self, table, type):
-        isPrivate='';
+
+    def _get_count(self, table, type, extra):
+        isPrivate=''
+        extraQ=''
         if type == 'dataset':
             isPrivate=' and private = FALSE';
-        q = sqlalchemy.text(''' select count(*) from {name} where state='active' and type='{type}' {isPrivate};'''.format(name=table, type=type, isPrivate=isPrivate))
+
+        if extra:
+            extraQ = "where state='active' and type='{type}' {isPrivate}".format(type=type, isPrivate=isPrivate)
+
+        q = sqlalchemy.text(''' select count(*) from {name} {extra};'''.format(name=table, extra=extraQ))
         result = model.Session.connection().execute(q, entity_id=id).scalar()
         return result
 
     def dataset(self):
-        return json.dumps({'count': self._get_count('package', 'dataset')})
+        return json.dumps({'count': self._get_count('package', 'dataset', True)})
 
     def country(self):
-        return json.dumps({'count': self._get_count('"group"', 'group')})
+        return json.dumps({'count': self._get_count('"group"', 'group', True)})
+
+    def organization(self):
+        return json.dumps({'count': self._get_count('"group"', 'organization', True)})
 
     def source(self):
-        return json.dumps({'count': 20})
\ No newline at end of file
+        return json.dumps({'count': 20})
+
+    def tag(self):
+        return json.dumps({'count': self._get_count('tag', 'tag', False)})
+
+    def format(self):
+        q = sqlalchemy.text('''select count(distinct(format)) from resource where not format is null;''')
+        result = model.Session.connection().execute(q, entity_id=id).scalar()
+        return json.dumps({'count': result})
+
+    def license(self):
+        q = sqlalchemy.text('''select count(distinct(license_id)) from package where not license_id is null;''')
+        result = model.Session.connection().execute(q, entity_id=id).scalar()
+        return json.dumps({'count': result})
+
+    list = {
+        'groups':country,
+        'tags':tag,
+        'organization':organization,
+        'res_format':format,
+        'license_id':license
+    }
+
+
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/country_list_hardcoded.py b/ckanext-hdx_theme/ckanext/hdx_theme/country_list_hardcoded.py
--- a/ckanext-hdx_theme/ckanext/hdx_theme/country_list_hardcoded.py
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/country_list_hardcoded.py
@@ -21,6 +21,7 @@
                 u"Cape Verde",
                 u"Central African Republic",
                 u"Chad",
+                u"Colombia",
                 u"Comoros",
                 u"Congo",
                 u"Côte d'Ivoire",
diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/helpers.py b/ckanext-hdx_theme/ckanext/hdx_theme/helpers.py
--- a/ckanext-hdx_theme/ckanext/hdx_theme/helpers.py
+++ b/ckanext-hdx_theme/ckanext/hdx_theme/helpers.py
@@ -6,10 +6,12 @@
 import sqlalchemy
 import ckan.logic as logic
 import datetime
+import count
+import json
 from webhelpers.html import escape, HTML, literal, url_escape
 
 downloadable_formats = {
-    'csv', 'xls', 'txt', 'jpg', 'jpeg', 'png', 'gif', 'zip', 'xml'
+    'csv', 'xls', 'xlsx', 'txt', 'jpg', 'jpeg', 'png', 'gif', 'zip', 'xml'
 }
 
 def is_downloadable(resource):
@@ -20,8 +22,13 @@ def is_downloadable(resource):
 
 def get_facet_items_dict(facet, limit=10, exclude_active=False):
     facets = h.get_facet_items_dict(facet, limit, exclude_active=exclude_active)
-    no_items = c.search_facets.get(facet)['items'].__len__()
-    
+    filtered_no_items = c.search_facets.get(facet)['items'].__len__()
+    total_no_items=json.loads(count.CountController.list[facet](count.CountController()))['count']
+    if filtered_no_items < 50 and filtered_no_items < total_no_items:
+        no_items=filtered_no_items
+    else:
+        no_items=total_no_items
+
     if c.search_facets_limits:
         limit = c.search_facets_limits.get(facet)
     if limit:


Test patch: