From a00fb65758dc56ffb6e5c3c16c36b9b629d34ca1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 28 Mar 2020 17:15:58 -0700 Subject: [PATCH] Don't leave falsey values out of dict_to_params, let caller do it. Explicit is better than implicit and all that. --- .../etiquette_flask/backend/endpoints/photo_endpoints.py | 4 +++- frontends/etiquette_flask/backend/helpers.py | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py index 3f3fef0..9f7614d 100644 --- a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py @@ -425,7 +425,9 @@ def get_search_core(): if offset > 0: prev_params = original_params.copy() - prev_params['offset'] = max(0, offset - limit) + prev_offset = max(0, offset - limit) + if prev_offset > 0: + prev_params['offset'] = prev_offset prev_params = helpers.dict_to_params(prev_params) prev_page_url = '/search' + prev_params else: diff --git a/frontends/etiquette_flask/backend/helpers.py b/frontends/etiquette_flask/backend/helpers.py index c78e9b7..f6a214a 100644 --- a/frontends/etiquette_flask/backend/helpers.py +++ b/frontends/etiquette_flask/backend/helpers.py @@ -7,9 +7,8 @@ def dict_to_params(d): if not d: return '' - params = [f'{key}={value}' for (key, value) in d.items() if value] + params = [f'{key}={value}' for (key, value) in d.items()] params = '&'.join(params) - if params: - params = '?' + params + params = '?' + params return params