Skip to content
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

Check for searchview default types (#11546) #11547

Draft
wants to merge 3 commits into
base: dev/8.0.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions arches/app/search/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def get_filter(self, componentname):
else:
return None

def get_searchview_name(self):
def get_searchview_name(self, default_type=None):
searchview_component = []
if not self.request:
searchview_component_name = None
elif self.request.method == "POST":
Expand All @@ -89,20 +90,30 @@ def get_searchview_name(self):
searchview_component_name = self.request.GET.get("search-view", None)

if not searchview_component_name:
# get default search_view component
searchview_component = list(
filter(
lambda x: x.config.get("default", False)
and x.type == "search-view",
list(self.search_filters.values()),
if default_type: # e.g. "searchViewDefault"
searchview_component = list(
filter(
lambda x: x.config.get(default_type, False)
and x.type == "search-view",
list(self.search_filters.values()),
)
)
if not default_type or len(searchview_component) == 0:
searchview_component = list(
filter(
lambda x: x.config.get("default", False)
and x.type == "search-view",
list(self.search_filters.values()),
)
)
)[0]
searchview_component = searchview_component[0]
searchview_component_name = searchview_component.componentname

return searchview_component_name

def get_searchview_instance(self):
searchview_component_name = self.get_searchview_name()
def get_searchview_instance(self, **kwargs):
default_type = kwargs.get("default_type", None)
searchview_component_name = self.get_searchview_name(default_type=default_type)
return self.get_filter(searchview_component_name)

def create_search_query_dict(self, key_value_pairs: List[Tuple[str, Any]]):
Expand Down
4 changes: 3 additions & 1 deletion arches/app/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def get(self, request):
)
geocoding_providers = Geocoder.objects.all()
search_component_factory = SearchFilterFactory(request)
searchview_instance = search_component_factory.get_searchview_instance()
searchview_instance = search_component_factory.get_searchview_instance(
default_type="searchViewDefault"
)
search_components = searchview_instance.get_searchview_filters()

datatypes = DDataType.objects.all()
Expand Down