Skip to content

Commit c3fe0e9

Browse files
committed
allow search to keep existing filters
1 parent c1001df commit c3fe0e9

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

util/templates/objectlist.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
<div class="row">
88
<div class="col-sm-10">
9-
{% searchform terms %}
9+
{% get_querydict request as querydict %}
10+
{% searchform terms querydict %}
1011
{% gen_table page.object_list table_template %}
1112
<div class="centered">
1213
{% object_count page %}

util/templates/searchbar.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<form method="get">
44
<div class="input-group">
55
<input type="text" class="form-control input-sm" placeholder="Search" name="search" id="search" value="{{ terms }}">
6+
{% for key, value in querydict.items %}
7+
<input type="hidden" id="{{ key }}" name="{{ key }}" value="{{ value }}">
8+
{% endfor %}
69
<div class="input-group-btn">
710
<button class="btn btn-primary btn-sm" type="submit">{% bootstrap_icon "search" %}</button>
811
</div>

util/templatetags/common.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def object_count(page):
8585
return f'{page.paginator.count} {name}'
8686

8787

88+
@register.simple_tag
89+
def get_querydict(request):
90+
get = request.GET.copy()
91+
if 'page' in get:
92+
del get['page']
93+
if 'search' in get:
94+
del get['search']
95+
return get
96+
97+
8898
@register.simple_tag
8999
def get_querystring(request):
90100
get = request.GET.copy()
@@ -94,9 +104,9 @@ def get_querystring(request):
94104

95105

96106
@register.simple_tag
97-
def searchform(terms):
107+
def searchform(terms, querydict):
98108
template = get_template('searchbar.html')
99-
html = template.render({'post_url': '.', 'terms': terms})
109+
html = template.render({'post_url': '.', 'terms': terms, 'querydict': querydict})
100110
return html
101111

102112

0 commit comments

Comments
 (0)