Skip to content

Commit c37c535

Browse files
committed
[IEXP-595] retrain or reset box status for searches
1 parent 33ee759 commit c37c535

File tree

9 files changed

+211
-111
lines changed

9 files changed

+211
-111
lines changed

isiscb/isisdata/templates/isisdata/home_isiscb.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ <h2> An open access discovery service for the history of science.</h2>
108108
</span>
109109
</div>
110110
<div>
111-
<input id="id_models" name="models" type="hidden" value="isisdata.citation">
112111
<input id="id_sort_order_citation" maxlength="255" name="sort_order_citation" type="hidden" value="publication_date_for_sort">
113112
<input id="id_sort_order_dir_citation" maxlength="255" name="sort_order_dir_citation" type="hidden" value="descend">
114113
<input id="id_sort_order_authority" maxlength="255" name="sort_order_authority" type="hidden" value="citation_count">
@@ -131,7 +130,6 @@ <h2> An open access discovery service for the history of science.</h2>
131130
</span>
132131
</div>
133132
<div>
134-
<input id="id_models" name="models" type="hidden" value="isisdata.citation">
135133
<input id="id_sort_order_citation" maxlength="255" name="sort_order_citation" type="hidden" value="publication_date_for_sort">
136134
<input id="id_sort_order_dir_citation" maxlength="255" name="sort_order_dir_citation" type="hidden" value="descend">
137135
<input id="id_sort_order_authority" maxlength="255" name="sort_order_authority" type="hidden" value="citation_count">

isiscb/isisdata/templatetags/facet_filters.py

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ def set_excluded_facets(url, available_facets):
3030
exclude_str += 'excluded_facets=citation_type:' + facet_tuple[0] + "&"
3131
return (url+ '&' + exclude_str).replace("&&", "&")
3232

33+
@register.filter
34+
def remove_selected_facet(url, arg):
35+
path, qs = _get_path_and_qs(url)
36+
for para in qs:
37+
if para[0] == "selected_facets" and para[1] == arg:
38+
qs.remove(para)
39+
40+
return _build_final_url(path, qs)
41+
42+
3343
@register.filter
3444
def remove_url_part(url, arg):
3545
qs = urllib.parse.parse_qsl(url)
@@ -58,18 +68,13 @@ def add_selected_facet(url, facet):
5868

5969
@register.filter
6070
def remove_query(url):
61-
# we will probably have the path prefix before the query string
62-
parsed_url = urllib.parse.urlparse(url)
63-
query_string = parsed_url.query
64-
path = parsed_url.path
65-
66-
qs = urllib.parse.parse_qsl(query_string)
71+
path, qs = _get_path_and_qs(url)
72+
6773
for para in qs:
6874
if para[0] == "q":
6975
qs.remove(para)
7076

71-
full_qs = "&".join([f"{para[0]}={para[1]}" for para in qs])
72-
return path + "?" + full_qs if path else full_qs
77+
return _build_final_url(path, qs)
7378

7479

7580
@register.filter
@@ -109,20 +114,43 @@ def are_reviews_excluded(url):
109114

110115
@register.filter
111116
def is_limited_to_tech_culture(url):
112-
parsed_url = urllib.parse.urlparse(url)
113-
query_string = parsed_url.query
114-
path = parsed_url.path
115-
116-
qs = urllib.parse.parse_qsl(query_string)
117+
path, qs = _get_path_and_qs(url)
117118
for para in qs:
118119
if para[0] == "selected_facets" and para[1]=="citation_dataset_typed_names:Technology & Culture Bibliography":
119120
return True
120121
return False
121122

122123
@register.filter
123124
def limit_to_tech_culture_facet(url):
124-
return (url + "&selected_facets=citation_dataset_typed_names:Technology%20%26%20Culture%20Bibliography")
125+
path, qs = _get_path_and_qs(url)
126+
if not any(para[0] == "selected_facets" and \
127+
para[1]=="citation_dataset_typed_names:Technology & Culture Bibliography" \
128+
for para in qs
129+
):
130+
qs.append(("selected_facets","citation_dataset_typed_names:Technology & Culture Bibliography"))
131+
return _build_final_url(path, qs)
125132

133+
@register.filter
134+
def remove_tech_culture_facet(url):
135+
path, qs = _get_path_and_qs(url)
136+
for para in qs:
137+
if para[0] == "selected_facets" and para[1]=="citation_dataset_typed_names:Technology & Culture Bibliography":
138+
qs.remove(para)
139+
return _build_final_url(path, qs)
140+
141+
@register.filter
142+
def set_status_retain(url):
143+
"""
144+
If this parameter is set, the search should maintain all panel statuses (which filters are open
145+
and selected and which ones are not).
146+
"""
147+
path, qs = _get_path_and_qs(url)
148+
for para in qs:
149+
if para[0] == 'state':
150+
qs.remove(para)
151+
qs.append(('state', 'retain'))
152+
153+
return _build_final_url(path, qs)
126154

127155
@register.filter
128156
def are_stubs_excluded(url):
@@ -135,3 +163,24 @@ def add_excluded_stub_record_status_facet(url, facet):
135163
url = url.replace('selected_facets=' + facet_str, '')
136164
url = url + '&excluded_facets=' + facet_str
137165
return url.replace('&&', '&')
166+
167+
def _get_path_and_qs(url):
168+
# we will probably have the path prefix before the query string
169+
parsed_url = urllib.parse.urlparse(url)
170+
query_string = parsed_url.query
171+
path = parsed_url.path
172+
173+
qs = urllib.parse.parse_qsl(query_string)
174+
return path, qs
175+
176+
def _build_final_url(path, qs):
177+
"""
178+
Build a full url from a path prefix and a query string list.
179+
E.g.:
180+
path: /p/isiscb
181+
qs: [('state', 'retain'), ('selected_facets', 'Review')]
182+
becomes
183+
/p/isiscb?state=retain&selected_facets=Review
184+
"""
185+
full_qs = "&".join([f"{para[0]}={urllib.parse.quote(para[1])}" for para in qs])
186+
return path + "?" + full_qs if path else full_qs

isiscb/isisdata/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ def extra_context(self):
10351035
extra['count_citation'] = len(self.queryset['citation'])
10361036
extra['count_authority'] = len(self.queryset['authority'])
10371037

1038-
extra['models'] = self.request.GET.getlist('models')
1038+
# I don't think we need this anymore, since we always search for both models (IEXP-595)
1039+
#extra['models'] = self.request.GET.getlist('models')
10391040
extra['sort_order_citation'] = self.request.GET.get('sort_order_citation')
10401041
extra['sort_order_authority'] = self.request.GET.get('sort_order_authority')
10411042
extra['sort_order_dir_citation'] = self.request.GET.get('sort_order_dir_citation')

isiscb/tenants/templates/tenants/_navigation_search.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@
5151
</span>
5252
</div>
5353
<div>
54-
<input id="id_models" name="models" type="hidden" value="isisdata.citation">
5554
<input id="id_sort_order_citation" maxlength="255" name="sort_order_citation" type="hidden" value="publication_date_for_sort">
5655
<input id="id_sort_order_dir_citation" maxlength="255" name="sort_order_dir_citation" type="hidden" value="descend">
5756
<input id="id_sort_order_authority" maxlength="255" name="sort_order_authority" type="hidden" value="citation_count">
5857
<input id="id_sort_order_dir_authority" maxlength="255" name="sort_order_dir_authority" type="hidden" value="descend">
59-
58+
<input name="state" value="refresh" type="hidden" />
6059
<input id="id_excluded_facets" maxlength="255" name="excluded_facets" type="hidden" value="citation_type:Review">
6160
<input name="owning_tenant" type="hidden" value="{{ tenant_id }}" />
6261
<input name="tenant_portal" type="hidden" value="{{ tenant_id }}" />

isiscb/tenants/templates/tenants/home.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ <h2 style="font-weight: 400; margin-bottom: 50px">{{ tenant.settings.home_main_b
126126
</span>
127127
</div>
128128
<div>
129-
<input id="id_models" name="models" type="hidden" value="isisdata.citation">
130129
<input id="id_sort_order_citation" maxlength="255" name="sort_order_citation" type="hidden" value="publication_date_for_sort">
131130
<input id="id_sort_order_dir_citation" maxlength="255" name="sort_order_dir_citation" type="hidden" value="descend">
132131
<input id="id_sort_order_authority" maxlength="255" name="sort_order_authority" type="hidden" value="citation_count">

0 commit comments

Comments
 (0)