Skip to content

Commit

Permalink
fix: test if status.index route exists
Browse files Browse the repository at this point in the history
  • Loading branch information
alycejenni committed Jul 12, 2024
1 parent b3cfdd9 commit 95303c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 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
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 95303c2

Please sign in to comment.