-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
11578 make search-filters request.method agnostic #11582
base: dev/7.6.x
Are you sure you want to change the base?
Changes from all commits
c4023c1
0315aac
6599a43
30e3dac
fa81b4f
a1f34c4
e68f68b
9f46aa9
9abbbba
3efea56
de2dd67
52a7b05
127d1d4
72289c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,11 @@ | |
|
||
|
||
class BaseSearchFilter: | ||
def __init__(self, request=None, user=None, componentname=None): | ||
def __init__( | ||
self, request=None, search_request=None, user=None, componentname=None | ||
): | ||
self.request = request | ||
self.search_request = search_request | ||
self.user = user | ||
self.componentname = componentname | ||
|
||
|
@@ -54,6 +57,10 @@ def __init__(self, request=None, user=None): | |
for search_filter in SearchComponent.objects.all() | ||
} | ||
self.search_filters_instances = {} | ||
request_object = ( | ||
self.request.GET if self.request.method == "GET" else self.request.POST | ||
) | ||
self.search_request = request_object.dict() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we should rename this to "self.querystring" because essentially that's what it is. This would reduce confusion with "self.request" |
||
|
||
def get_filter(self, componentname): | ||
if componentname in self.search_filters: | ||
|
@@ -71,7 +78,7 @@ def get_filter(self, componentname): | |
) | ||
if class_method: | ||
filter_instance = class_method( | ||
self.request, self.user, componentname | ||
self.request, self.search_request, self.user, componentname | ||
) | ||
self.search_filters_instances[search_filter.componentname] = ( | ||
filter_instance | ||
|
@@ -83,10 +90,8 @@ def get_filter(self, componentname): | |
def get_searchview_name(self): | ||
if not self.request: | ||
searchview_component_name = None | ||
elif self.request.method == "POST": | ||
searchview_component_name = self.request.POST.get("search-view", None) | ||
else: | ||
searchview_component_name = self.request.GET.get("search-view", None) | ||
searchview_component_name = self.search_request.get("search-view", None) | ||
Comment on lines
91
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we only need the "else" portion of this statement. self.request is already assumed to exist in the |
||
|
||
if not searchview_component_name: | ||
# get default search_view component | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,8 +48,15 @@ class BaseSearchView(BaseSearchFilter): | |
how to execute a search in the search_results method | ||
""" | ||
|
||
def __init__(self, request=None, user=None, componentname=None): | ||
super().__init__(request=request, user=user, componentname=componentname) | ||
def __init__( | ||
self, request=None, search_request=None, user=None, componentname=None | ||
): | ||
super().__init__( | ||
request=request, | ||
search_request=search_request, | ||
user=user, | ||
componentname=componentname, | ||
) | ||
self.searchview_component = SearchComponent.objects.get( | ||
componentname=componentname | ||
) | ||
|
@@ -95,6 +102,7 @@ def __init__(self, request=None, user=None, componentname=None): | |
item.componentname, float("inf") | ||
), | ||
) | ||
self.search_request = self.create_query_dict(self.search_request) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt this is neccessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also due to the inheritance logic of search-view classes, setting the correct search-view on a blank request here: def create_query_dict(self, query_dict):
# check that all searchview required linkedSearchFilters are present
query_dict[self.searchview_component.componentname] = True # set the database default search-view ... is what enables the python class of that search-view to be initialized. I know it looks circular but this came about as an intentional fix. |
||
|
||
@property | ||
def required_search_filters(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
class SortResults(BaseSearchFilter): | ||
def append_dsl(self, search_query_object, **kwargs): | ||
sort_param = self.request.GET.get(self.componentname, None) | ||
sort_param = kwargs.get("querystring", None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be
|
||
|
||
if sort_param is not None and sort_param != "": | ||
search_query_object["query"].sort( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,16 +46,28 @@ class SearchResultsExporter(object): | |
def __init__(self, search_request=None): | ||
if search_request is None: | ||
raise Exception("Need to pass in a search request") | ||
search_request.GET = search_request.GET.copy() | ||
search_request.GET["tiles"] = True | ||
search_request.GET["export"] = True | ||
self.report_link = search_request.GET.get("reportlink", False) | ||
self.format = search_request.GET.get("format", "tilecsv") | ||
self.export_system_values = get_str_kwarg_as_bool( | ||
"exportsystemvalues", search_request.GET | ||
) | ||
self.compact = search_request.GET.get("compact", True) | ||
self.precision = int(search_request.GET.get("precision", 5)) | ||
if search_request.method == "GET": | ||
search_request.GET = search_request.GET.copy() | ||
search_request.GET["tiles"] = True | ||
search_request.GET["export"] = True | ||
self.report_link = search_request.GET.get("reportlink", False) | ||
self.format = search_request.GET.get("format", "tilecsv") | ||
self.export_system_values = get_str_kwarg_as_bool( | ||
"exportsystemvalues", search_request.GET | ||
) | ||
self.compact = search_request.GET.get("compact", True) | ||
self.precision = int(search_request.GET.get("precision", 5)) | ||
else: | ||
search_request.POST = search_request.POST.copy() | ||
search_request.POST["tiles"] = True | ||
search_request.POST["export"] = True | ||
self.report_link = search_request.POST.get("reportlink", False) | ||
self.format = search_request.POST.get("format", "tilecsv") | ||
self.export_system_values = get_str_kwarg_as_bool( | ||
"exportsystemvalues", search_request.POST | ||
) | ||
self.compact = search_request.POST.get("compact", True) | ||
self.precision = int(search_request.POST.get("precision", 5)) | ||
Comment on lines
+49
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this if/else could be boiled down to a single chunk of code using something like this:
|
||
if self.format == "shp" and self.compact is not True: | ||
raise Exception("Results must be compact to export to shapefile") | ||
self.search_request = search_request | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
from django.http import Http404 | ||
from django.shortcuts import render | ||
from django.utils.translation import gettext as _ | ||
from django.views.decorators.csrf import csrf_exempt | ||
from arches.app.models.models import ( | ||
MapMarker, | ||
GraphModel, | ||
|
@@ -349,6 +350,7 @@ def get_dsl_from_search_string(request): | |
return JSONResponse(dsl) | ||
|
||
|
||
@csrf_exempt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the need for this? |
||
def search_results(request, returnDsl=False): | ||
search_filter_factory = SearchFilterFactory(request) | ||
searchview_component_instance = search_filter_factory.get_searchview_instance() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where did this number come from? 2048 seems like the most Edge can handle but most other browsers much more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaves a generous buffer in case the host is really long as can sometimes be the case with development hosts using Azure, for example: "https://longsubdomain.azure.cloudapp.westus3.developmentserverlongname." Is there a reason you think we should increase this limit + forego compatibility with Edge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe another option is to build the full GET URL string and compare that to the 2048 limit? May need to URL Encode the query string to as that can add a large number of characters to the URL (eg: " " -> "%20", etc).
Something like this might work to get the full URL length?:
Also - there's at least one other place that we'll need to handle this on the front end. Maybe worth wrapping the logic in a separate util function as it feels like this may be implemented in a number of places?
arches/arches/app/media/js/views/components/search/search-export.js
Lines 77 to 80 in debacb9