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/theme/templates/header.html b/ckanext/nhm/theme/templates/header.html index 8fad5f5e..3943dc0c 100755 --- a/ckanext/nhm/theme/templates/header.html +++ b/ckanext/nhm/theme/templates/header.html @@ -9,6 +9,7 @@ {% set status_indicator = h.get_status_indicator() %} {% macro status_icon() %} +{% if h.route_exists('status.index') %}
@@ -22,6 +23,7 @@
+{% endif %} {% endmacro %}