Reformat and don't pass back default parameters to URL

This commit is contained in:
2022-09-05 07:20:30 +01:00
parent ba57c378cd
commit 11dbe3e094
64 changed files with 3843 additions and 3867 deletions

View File

@@ -9,6 +9,7 @@
# from sortedcontainers import SortedSet
# from core import r
from django.conf import settings
class SearchDenied:
@@ -23,6 +24,19 @@ class LookupDenied:
self.value = value
def remove_defaults(query_params):
for field, value in list(query_params.items()):
if field in settings.DRILLDOWN_DEFAULT_PARAMS:
if value == settings.DRILLDOWN_DEFAULT_PARAMS[field]:
del query_params[field]
def add_defaults(query_params):
for field, value in settings.DRILLDOWN_DEFAULT_PARAMS.items():
if field not in query_params:
query_params[field] = value
def dedup_list(data, check_keys):
"""
Remove duplicate dictionaries from list.

View File

@@ -21,6 +21,7 @@ from core.lib.threshold import (
get_chans,
get_users,
)
from core.views import helpers
from core.views.ui.tables import DrilldownTable
# from copy import deepcopy
@@ -155,11 +156,6 @@ def drilldown_search(request, return_context=False, template=None):
# else:
# context = {"object_list": []}
# Remove null values
if "query_full" in query_params:
if query_params["query_full"] == "":
del query_params["query_full"]
if "tags" in query_params:
if query_params["tags"] == "":
del query_params["tags"]
@@ -172,7 +168,9 @@ def drilldown_search(request, return_context=False, template=None):
# Valid sizes
context["sizes"] = sizes
print("BEFORE REMOVE DEFAULT", query_params)
helpers.remove_defaults(query_params)
print("AFTER REMOVE DEFAULT", query_params)
url_params = urllib.parse.urlencode(query_params)
context["client_uri"] = url_params
context["params"] = query_params
@@ -199,17 +197,6 @@ def drilldown_search(request, return_context=False, template=None):
clean_url_params = urllib.parse.urlencode(clean_params)
context["uri"] = clean_url_params
# Warn users trying to use query string that the simple query supersedes it
if all([x in query_params for x in ["query", "query_full"]]):
context["message"] = (
"You are searching with both query types. "
"The simple query will be used. "
"The full query will be ignored. "
"Remove the text from the simple query if you wish "
"to use the full query."
)
context["class"] = "warning"
# unique = str(uuid.uuid4())[:8]
if return_context:
return context