From c55f18efd3d2ead0d7f3a3a418771517601cdbf5 Mon Sep 17 00:00:00 2001
From: anonymous <anonymous>
Date: Mon, 6 May 2019 15:53:40 +0200
Subject: [PATCH] ODPSH-383

---
 ckanext/odsh/plugin.py                        | 28 +++++++++++++++++++
 .../odsh/templates/snippets/facet_list.html   |  2 +-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py
index 5db0f85d..335544fa 100644
--- a/ckanext/odsh/plugin.py
+++ b/ckanext/odsh/plugin.py
@@ -21,9 +21,36 @@ import ckan.plugins as p
 import logging
 import validation
 import precondition
+ 
+import sys
 
 log = logging.getLogger(__name__)
 
+# from functools import wraps
+# from flask import Flask, redirect, jsonify
+# app = Flask(__name__)
+
+# def get_http_exception_handler(app):
+#     """Overrides the default http exception handler to return JSON."""
+#     handle_http_exception = app.handle_http_exception
+#     @wraps(handle_http_exception)
+#     def ret_val(exception):
+#         print("HEHREHR")
+#         exc = handle_http_exception(exception)    
+#         return jsonify({'code':exc.code, 'message':exc.description}), exc.code
+#     return ret_val
+
+# # Override the HTTP exception handler.
+# app.handle_http_exception = get_http_exception_handler(app)
+
+
+# def my_except_hook(exctype, value, traceback):
+#     print('GOT excepton')
+#     log.exception(value)
+#     sys.__excepthook__(exctype, value, traceback)
+# print('INSTALL EX')
+# sys.excepthook = my_except_hook
+
 _ = toolkit._
 
 from multiline_formatter.formatter import MultilineMessagesFormatter
@@ -354,6 +381,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
     # use several daterange queries agains temporal_start and temporal_end field
     # TODO: use field of type date_range in solr index instead
     def before_search(self, search_params):
+        search_params['facet.mincount']=0
         extras = search_params.get('extras')
         if not extras:
             # There are no extras in the search params, so do nothing.
diff --git a/ckanext/odsh/templates/snippets/facet_list.html b/ckanext/odsh/templates/snippets/facet_list.html
index 985003d4..38a8e1a4 100644
--- a/ckanext/odsh/templates/snippets/facet_list.html
+++ b/ckanext/odsh/templates/snippets/facet_list.html
@@ -7,7 +7,7 @@
 
 {% block facet_list_items %}
 {# {% with items = items or h.get_facet_items_dict(name,20) %} #}
-{% with items = items or h.odsh_get_facet_items_dict(name) %}
+{% with items = items or h.odsh_get_facet_items_dict(name)|selectattr('count')|list %}
 {% if items %}
 <nav>
   {% set title = title or h.get_facet_title(name) %}
-- 
GitLab