diff --git a/ckanext/nhm/lib/helpers.py b/ckanext/nhm/lib/helpers.py index d434e6cc..ec02c72d 100644 --- a/ckanext/nhm/lib/helpers.py +++ b/ckanext/nhm/lib/helpers.py @@ -19,6 +19,7 @@ from beaker.cache import cache_region from jinja2.filters import do_truncate from lxml import etree, html +from werkzeug.routing import BuildError from ckan import model from ckan.lib import helpers as core_helpers @@ -1627,3 +1628,17 @@ def get_status_indicator(): amber_status = [r for r in status_reports if r['state'] == 'ok'] if len(amber_status) > 0: return 'amber' + + +def route_exists(route): + """ + Simple helper for checking if a flask route exists. + + :param route: endpoint name, as passed to url_for + :return: bool + """ + try: + url = toolkit.url_for(route) + return True + except BuildError: + return False \ No newline at end of file diff --git a/ckanext/nhm/lib/utils.py b/ckanext/nhm/lib/utils.py index 01278043..89d6c03a 100644 --- a/ckanext/nhm/lib/utils.py +++ b/ckanext/nhm/lib/utils.py @@ -6,17 +6,22 @@ from ckan.plugins import toolkit import requests +from cachetools import cached, TTLCache +@cached(cache=TTLCache(maxsize=10, ttl=300)) def get_iiif_status(): - health = {} + health = {'ping': False} url = toolkit.config.get('ckanext.iiif.image_server_url') - r = requests.get(url + '/status') - if r.ok: - health['ping'] = True - response_json = r.json() - else: + try: + r = requests.get(url + '/status', timeout=5) + if r.ok: + health['ping'] = True + response_json = r.json() + else: + response_json = {} + except requests.exceptions.RequestException as e: response_json = {} health['status'] = response_json.get('status') diff --git a/ckanext/nhm/theme/assets/scripts/bbcm.js b/ckanext/nhm/theme/assets/scripts/bbcm.js index 257fab95..f2365210 100644 --- a/ckanext/nhm/theme/assets/scripts/bbcm.js +++ b/ckanext/nhm/theme/assets/scripts/bbcm.js @@ -225,8 +225,6 @@ function createPopup(latlng, specs) { baseUrl + '/object/' + specimen.occurrenceID + - '/' + - version.toString() + '">View on the Data Portal'; popupContent += ''; diff --git a/ckanext/nhm/theme/templates/bbcm.html b/ckanext/nhm/theme/templates/bbcm.html index 69dd10ba..925603cc 100644 --- a/ckanext/nhm/theme/templates/bbcm.html +++ b/ckanext/nhm/theme/templates/bbcm.html @@ -15,23 +15,6 @@ {%- block page %} {{ super() }} - - -