Skip to content

Commit

Permalink
merge: PR #790 from dev
Browse files Browse the repository at this point in the history
Weekly release 2024-07-15
  • Loading branch information
alycejenni authored Jul 15, 2024
2 parents fc18ec1 + 6d3acb6 commit 10d9551
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
15 changes: 15 additions & 0 deletions ckanext/nhm/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 11 additions & 6 deletions ckanext/nhm/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 0 additions & 2 deletions ckanext/nhm/theme/assets/scripts/bbcm.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ function createPopup(latlng, specs) {
baseUrl +
'/object/' +
specimen.occurrenceID +
'/' +
version.toString() +
'">View on the Data Portal</a>';
popupContent += '</div>';

Expand Down
17 changes: 0 additions & 17 deletions ckanext/nhm/theme/templates/bbcm.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@

{%- block page %}
{{ super() }}
<!-- GA -->
<script>
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
'gtm.start':
new Date().getTime(), event: 'gtm.js'
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src =
'//www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-5MDTTC');
</script>

<div id="map"></div>

<div id="details">
Expand Down
2 changes: 2 additions & 0 deletions ckanext/nhm/theme/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{% set status_indicator = h.get_status_indicator() %}
{% macro status_icon() %}
{% if h.route_exists('status.index') %}
<div>
<a href="{{ h.url_for('status.index') }}"
title="{{ _('System status') }}">
Expand All @@ -22,6 +23,7 @@
<i class="fas fa-heartbeat fa-lg"></i>
</a>
</div>
{% endif %}
{% endmacro %}


Expand Down

0 comments on commit 10d9551

Please sign in to comment.