Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate ao_is_pending boolean type
Browse files Browse the repository at this point in the history
pkfec committed Jan 8, 2025
1 parent 2b3abbd commit ff65d62
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 13 additions & 1 deletion webservices/filters.py
Original file line number Diff line number Diff line change
@@ -197,5 +197,17 @@ def validate_ao_requestor_type(ao_requestor_type):
if isinstance(value, str) and ' ' not in value:
if value in ao_requestor_type_valid_filter_values:
valid_values.append(value)
return valid_values

return valid_values

def validate_boolean_dropdown(value):
# If value is None or an empty string, treat it as False
if value is None or value == "":
return False

# If the value is a boolean, return it as is
if isinstance(value, bool):
return value

# Return False if the value is not a boolean, None, or empty string
return False
13 changes: 9 additions & 4 deletions webservices/resources/legal.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
logger = logging.getLogger(__name__)

# To debug, uncomment the line below:
# logger.setLevel(logging.DEBUG)
logger.setLevel(logging.DEBUG)

es_client = create_es_client()

@@ -604,8 +604,12 @@ def apply_ao_specific_query_params(query, **kwargs):
if check_filter_exists(kwargs, "ao_name"):
must_clauses.append(Q("match", name=" ".join(kwargs.get("ao_name"))))

if kwargs.get("ao_is_pending") is not None:
must_clauses.append(Q("term", is_pending=kwargs.get("ao_is_pending")))
# if kwargs.get("ao_is_pending") is not None:
# must_clauses.append(Q("term", is_pending=kwargs.get("ao_is_pending")))

ao_pending_boolean = kwargs.get("ao_is_pending")
if filters.validate_boolean_dropdown(ao_pending_boolean):
must_clauses.append(Q("term", is_pending=ao_pending_boolean))

if kwargs.get("ao_status"):
must_clauses.append(Q("match", status=kwargs.get("ao_status")))
@@ -788,7 +792,8 @@ def execute_query(query):
def check_filter_exists(kwargs, filter):
if kwargs.get(filter):
for val in kwargs.get(filter):
if len(val) > 0:
# if len(val) > 0:
if (len(val) > 0) and ('' not in val):
return True
return False
else:

0 comments on commit ff65d62

Please sign in to comment.