Skip to content

Commit

Permalink
put count threshold integer in its own message
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfk committed Jan 22, 2024
1 parent 36db4aa commit 3d39e7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 7 additions & 2 deletions bento_beacon/utils/beacon_response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import current_app, g, request
from .katsu_utils import search_summary_statistics, overview_statistics
from .censorship import get_censorship_threshold, censored_count, no_results_censorship_message
from .censorship import get_censorship_threshold, censored_count, MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS
from .exceptions import InvalidQuery, APIException
from ..constants import GRANULARITY_BOOLEAN, GRANULARITY_COUNT, GRANULARITY_RECORD

Expand All @@ -21,6 +21,11 @@ def add_message(message_obj):
g.response_info["messages"] = messages


def add_no_results_censorship_message_to_response():
add_info_to_response(MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS)
add_info_to_response(f"censorship threshold: {current_app.config['COUNT_THRESHOLD']}")


def add_stats_to_response(ids):
if ids is not None and len(ids) <= get_censorship_threshold():
return
Expand Down Expand Up @@ -109,7 +114,7 @@ def build_query_response(ids=None, numTotalResults=None, full_record_handler=Non
count = len(ids) if numTotalResults is None else numTotalResults
returned_count = censored_count(count)
if returned_count == 0 and get_censorship_threshold() > 0:
add_info_to_response(no_results_censorship_message())
add_no_results_censorship_message_to_response()
if granularity == GRANULARITY_BOOLEAN:
return beacon_boolean_response(returned_count)
if granularity == GRANULARITY_COUNT:
Expand Down
6 changes: 1 addition & 5 deletions bento_beacon/utils/censorship.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
from .exceptions import APIException, InvalidQuery


def no_results_censorship_message():
return (
"No results. Either none were found, or the query produced results numbering at "
f"or below the threshold for censorship ({current_app.config['COUNT_THRESHOLD']} items)"
)
MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS = "No results. Either none were found, or the query produced results numbering at or below the threshold for censorship."


def get_censorship_threshold():
Expand Down

0 comments on commit 3d39e7a

Please sign in to comment.