Skip to content

Commit

Permalink
Only load Algolia if we have a key
Browse files Browse the repository at this point in the history
  • Loading branch information
anorthall committed Apr 28, 2024
1 parent 0c8555f commit 9643e24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions reportdb/core/context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ def algolia_search_key(_: HttpRequest) -> dict[str, Any]:
return {
"ALGOLIA_APPLICATION_ID": settings.ALGOLIA_APPLICATION_ID,
"ALGOLIA_SEARCH_KEY": settings.ALGOLIA_SEARCH_KEY,
"ALGOLIA_ENABLED": settings.ALGOLIA_ENABLED,
}
6 changes: 5 additions & 1 deletion reportdb/reportdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"debug_toolbar",
"django_htmx",
"active_link",
"algoliasearch_django",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down Expand Up @@ -225,6 +224,11 @@
"API_KEY": ALGOLIA_API_KEY,
}

ALGOLIA_ENABLED = False

if ALGOLIA_APPLICATION_ID and ALGOLIA_SEARCH_KEY and ALGOLIA_API_KEY:
INSTALLED_APPS.append("algoliasearch_django")
ALGOLIA_ENABLED = True

# Google Tag Manager
GOOGLE_GTM_TAG = os.environ.get("GOOGLE_GTM_TAG", "")
5 changes: 4 additions & 1 deletion reportdb/templates/_nav_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ <h5 class="header">Tasks <small>{{ total_tasks }}</small></h5>

<h5 class="header">Project</h5>

<a class="nav-link {% active_link "db:search" %}" href="{% url "db:search" %}">Search</a>
{% if ALGOLIA_ENABLED %}
<a class="nav-link {% active_link "db:search" %}" href="{% url "db:search" %}">Search</a>
{% endif %}

<a class="nav-link {% active_link "db:help" %}" href="{% url "db:help" %}">Help</a>
<a class="nav-link {% active_link "db:about" %}" href="{% url "db:about" %}">About</a>
<a class="nav-link" href="{% url "db:random_incident" %}">Random</a>
Expand Down

0 comments on commit 9643e24

Please sign in to comment.