Commit c2830c20 authored by felix.herrmann's avatar felix.herrmann
Browse files

fix(search): add template tag for creating GET url parameters from a...

fix(search): add template tag for creating GET url parameters from a dictionary created in search view
parent 98d296ec
......@@ -220,3 +220,20 @@ def get_curators_page(context):
except ManualPage.DoesNotExist:
curators_page = None
return curators_page
@register.filter
def add_url_search_params(search_params_dict):
""" add search params from a dictionary of lists to an url
"""
params_string = "?q="
query = search_params_dict["q"]
if query:
params_string += query
for key, value in search_params_dict.items():
if key != "q":
if value:
for entry in value:
params_string += "&{}={}".format(key, entry)
return params_string
......@@ -145,6 +145,11 @@ def core_search_view(request, search_index, objects_on_page):
else:
objects = queryset
search_params = dict()
search_params["countries"] = countries
search_params["categories"] = categories
search_params["q"] = query
return render(
request,
template,
......@@ -153,6 +158,7 @@ def core_search_view(request, search_index, objects_on_page):
"pagination": pagination,
"paginator_range": paginator_range,
"paginator_last_page": paginator_last_page,
"search_params": search_params,
"countries": countries,
"countries_all": countries_all,
"categories": categories,
......
......@@ -59,13 +59,13 @@
<h2>{% trans "Filters" %}</h2>
{# search_index #}
{% include 'core/_search_index.html' with filters=search_index filters_all=search_index_all filter_applied="user_index" %}
{% include 'core/_search_index.html' with filters=search_index filters_all=search_index_all filter_applied="user_index" search_params=search_params %}
{# countries #}
{% include 'core/_search_filter.html' with filters=countries filters_all=countries_all filtertype="countries" %}
{% include 'core/_search_filter.html' with filters=countries filters_all=countries_all filtertype="countries" search_params=search_params %}
{# categories #}
{% include 'core/_search_filter.html' with filters=categories filters_all=categories_all filtertype="categories" %}
{% include 'core/_search_filter.html' with filters=categories filters_all=categories_all filtertype="categories" search_params=search_params %}
</form>
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment