Skip to content

Commit

Permalink
Update the type=all logic to return all types when the search is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pkfec committed Jan 16, 2025
1 parent 5de8d70 commit 1290d3e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions webservices/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ def make_seek_args(field=fields.Int, description=None):
'from_hit': fields.Int(required=False, description=docs.FROM_HIT),
'hits_returned': fields.Int(required=False, description=docs.HITS_RETURNED),
'type': fields.Str(
validate=validate.OneOf(["admin_fines", "adrs", "advisory_opinions",
"murs", "statutes"]),
validate=validate.OneOf(['', 'admin_fines', 'adrs', 'advisory_opinions',
'murs', 'statutes']),
description=docs.LEGAL_DOC_TYPE),

'ao_no': fields.List(IStr, required=False, description=docs.AO_NUMBER),
Expand Down
20 changes: 8 additions & 12 deletions webservices/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,13 @@ def get_cycle(kwargs):
return kwargs['cycle']


ao_requestor_type_valid_filter_values = ['1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16']
def validate_multiselect_filter(filter, valid_values):
valid_results = []


def validate_ao_requestor_type(ao_requestor_type):
valid_values = []

# Validate each value in ao_requestor_type
for value in ao_requestor_type:
# Validate each value in filter
for value in filter:
if isinstance(value, str) and ' ' not in value:
if value in ao_requestor_type_valid_filter_values:
valid_values.append(value)

return valid_values
if value in valid_values:
valid_results.append(value)
print("Valid_Values::::::", valid_results)
return valid_results
15 changes: 11 additions & 4 deletions webservices/resources/legal.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def get(self, q="", from_hit=0, hits_returned=20, **kwargs):
"adrs": case_query_builder,
"admin_fines": case_query_builder,
}

if kwargs.get("type", "all") == "all":
# Get the type from kwargs, defaulting to '' if not present
if kwargs.get("type", "") == "":
doc_types = ALL_DOCUMENT_TYPES
else:
doc_types = [kwargs.get("type")]
Expand Down Expand Up @@ -658,6 +658,10 @@ def apply_ao_specific_query_params(query, **kwargs):
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")))

Expand Down Expand Up @@ -739,9 +743,12 @@ def apply_ao_specific_query_params(query, **kwargs):

# Get 'ao_requestor_type' from kwargs
ao_requestor_type = kwargs.get("ao_requestor_type", [])
ao_requestor_type_valid_values = ['1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16']

# Validate 'ao_requestor_type'
valid_requestor_types = filters.validate_ao_requestor_type(ao_requestor_type)
# Validate 'ao_requestor_type filter'
valid_requestor_types = filters.validate_multiselect_filter(
ao_requestor_type, ao_requestor_type_valid_values)

# Always include valid values in the query construction
if valid_requestor_types:
Expand Down

0 comments on commit 1290d3e

Please sign in to comment.