From 25a27e6241bd015886a82bf567117c10ff366693 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 4 Nov 2018 13:30:08 -0800 Subject: [PATCH] Move dict_to_params to flask-specific helpers.py. The rest of etiquette has nothing to do with URLs so this doesn't belong in the backend helper file. --- etiquette/helpers.py | 16 ---------------- .../etiquette_flask/endpoints/photo_endpoints.py | 5 +++-- .../etiquette_flask/etiquette_flask/helpers.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 frontends/etiquette_flask/etiquette_flask/helpers.py diff --git a/etiquette/helpers.py b/etiquette/helpers.py index 5db325a..bd60d1a 100644 --- a/etiquette/helpers.py +++ b/etiquette/helpers.py @@ -122,22 +122,6 @@ def comma_space_split(s): s = [x for x in s if x] return s -def dict_to_params(d): - ''' - Given a dictionary of URL parameters, return a URL parameter string. - - {'a':1, 'b':2} -> '?a=1&b=2' - ''' - if not d: - return '' - - params = [f'{key}={value}' for (key, value) in d.items() if value] - params = '&'.join(params) - if params: - params = '?' + params - - return params - def fit_into_bounds(image_width, image_height, frame_width, frame_height): ''' Given the w+h of the image and the w+h of the frame, diff --git a/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py b/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py index 6824ce8..62ff5a7 100644 --- a/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py +++ b/frontends/etiquette_flask/etiquette_flask/endpoints/photo_endpoints.py @@ -9,6 +9,7 @@ from voussoirkit import cacheclass from .. import common from .. import decorators +from .. import helpers from .. import jsonify site = common.site @@ -396,7 +397,7 @@ def get_search_core(): if len(photos) == limit: next_params = original_params.copy() next_params['offset'] = offset + limit - next_params = etiquette.helpers.dict_to_params(next_params) + next_params = helpers.dict_to_params(next_params) next_page_url = '/search' + next_params else: next_page_url = None @@ -404,7 +405,7 @@ def get_search_core(): if offset > 0: prev_params = original_params.copy() prev_params['offset'] = max(0, offset - limit) - prev_params = etiquette.helpers.dict_to_params(prev_params) + prev_params = helpers.dict_to_params(prev_params) prev_page_url = '/search' + prev_params else: prev_page_url = None diff --git a/frontends/etiquette_flask/etiquette_flask/helpers.py b/frontends/etiquette_flask/etiquette_flask/helpers.py new file mode 100644 index 0000000..c78e9b7 --- /dev/null +++ b/frontends/etiquette_flask/etiquette_flask/helpers.py @@ -0,0 +1,15 @@ +def dict_to_params(d): + ''' + Given a dictionary of URL parameters, return a URL parameter string. + + {'a':1, 'b':2} -> '?a=1&b=2' + ''' + if not d: + return '' + + params = [f'{key}={value}' for (key, value) in d.items() if value] + params = '&'.join(params) + if params: + params = '?' + params + + return params