Skip to content

Commit

Permalink
tss-2234: Saved Search bug (#856)
Browse files Browse the repository at this point in the history
Co-authored-by: abarolo <asmundbekker@DBT000435.local>
Co-authored-by: Uka Osim <uka.osim@digital.trade.gov.uk>
Co-authored-by: Feroze Rub <feroze@taridigital.com>
  • Loading branch information
4 people authored Dec 3, 2024
1 parent 204542a commit 8d959e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions barriers/forms/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ def get_remove_url(self, field_name):
return urlencode(params, doseq=True)

def get_api_search_parameters(self):

# Heres some comments to merge into develop
# This way we can check that changes to the develop branch
# do not trigger auto deployment to atlantis and gotham.

params = {}
params["search_id"] = self.cleaned_data.get("search_id")
params["search"] = self.cleaned_data.get("search")
Expand Down
6 changes: 1 addition & 5 deletions barriers/views/saved_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ def form_valid(self, form):
return HttpResponseRedirect(self.get_success_url(saved_search=saved_search))

def get_success_url(self, saved_search):
querystring = self.search_form.get_raw_filters_querystring()
return (
f"{reverse('barriers:search')}"
f"?search_id={saved_search.id}&{querystring}"
)
return f"{reverse('barriers:search')}?search_id={saved_search.id}"


class DeleteSavedSearch(SavedSearchMixin, TemplateView):
Expand Down
17 changes: 16 additions & 1 deletion barriers/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,22 @@ def get(self, request, *args, **kwargs):
return self.render_to_response(self.get_context_data(form=form))


class BarrierSearch(PaginationMixin, SearchFormView):
class BarrierSearchFormView(SearchFormView):
def get_form_kwargs(self):
search_id = self.request.GET.get("search_id")

kwargs = super().get_form_kwargs()

if search_id and len(self.request.GET) == 1:
# New saved search
saved_search = self.client.saved_searches.get(id=str(search_id))
kwargs["data"] = saved_search.filters
kwargs["data"]["search_id"] = search_id

return kwargs


class BarrierSearch(PaginationMixin, BarrierSearchFormView):
template_name = "barriers/search.html"
form_class = BarrierSearchForm
_client = None
Expand Down

0 comments on commit 8d959e5

Please sign in to comment.