diff --git a/hasjob/templates/index.html b/hasjob/templates/index.html
index ed7ab9a19..f5a45aa4e 100644
--- a/hasjob/templates/index.html
+++ b/hasjob/templates/index.html
@@ -174,7 +174,7 @@
What these jobs pay per annum
{%- if not paginated -%}
{% from "macros.html" import filters_setup_script %}
{%- if request.is_xhr -%}
- {{ filters_setup_script(job_location_filters, job_type_filters, job_category_filters) }}
+ {{ filters_setup_script(job_filters) }}
{%- if not paginated -%}
- {{ filters_setup_script(job_location_filters, job_type_filters, job_category_filters) }}
+ {{ filters_setup_script(job_filters) }}
{%- endif %}
{%- endblock %}
diff --git a/hasjob/templates/macros.html b/hasjob/templates/macros.html
index 6365debd6..9c70a5a08 100644
--- a/hasjob/templates/macros.html
+++ b/hasjob/templates/macros.html
@@ -187,18 +187,20 @@ {{ headline or post.headline }}
{{ campaign_header_postscript() }}
{% endmacro %}
-{% macro filters_setup_script(job_location_filters, job_type_filters, job_category_filters) %}
- {%- if (job_location_filters is defined) and (job_type_filters is defined) and (job_category_filters is defined) %}
-
- {%- endif %}
+{% macro filters_setup_script(job_filters) %}
+ {% with all_jobs_filters=job_filters() %}
+ {%- if (all_jobs_filters.job_location_filters is defined) and (all_jobs_filters.job_type_filters is defined) and (all_jobs_filters.job_category_filters is defined) %}
+
+ {%- endif %}
+ {%- endwith %}
{% endmacro %}
diff --git a/hasjob/views/helper.py b/hasjob/views/helper.py
index aa682b15c..4416d1a58 100644
--- a/hasjob/views/helper.py
+++ b/hasjob/views/helper.py
@@ -770,13 +770,17 @@ def inject_filter_options():
# Don't compute filter choices for paginated results
if index_is_paginated():
return dict()
- basequery = getposts(showall=True, order=False, limit=False)
- filters = g.get('event_data', {}).get('filters', {})
- cache_key = 'jobfilters/' + (g.board.name + '/' if g.board else '') + hashlib.sha1(repr(filters)).hexdigest()
- result = cache.get(cache_key)
- if not result:
- result = dict(job_location_filters=filter_locations(g.board, filters),
- job_type_filters=filter_types(basequery, board=g.board, filters=filters),
- job_category_filters=filter_categories(basequery, board=g.board, filters=filters))
- cache.set(cache_key, result, timeout=3600)
- return result
+
+ def get_job_filters():
+ basequery = getposts(showall=True, order=False, limit=False)
+ filters = g.get('event_data', {}).get('filters', {})
+ cache_key = 'jobfilters/' + (g.board.name + '/' if g.board else '') + hashlib.sha1(repr(filters)).hexdigest()
+ result = cache.get(cache_key)
+ if not result:
+ result = dict(job_location_filters=filter_locations(g.board, filters),
+ job_type_filters=filter_types(basequery, board=g.board, filters=filters),
+ job_category_filters=filter_categories(basequery, board=g.board, filters=filters))
+ cache.set(cache_key, result, timeout=3600)
+ return result
+
+ return dict(job_filters=get_job_filters)