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.
This commit is contained in:
parent
588bf59b88
commit
25a27e6241
3 changed files with 18 additions and 18 deletions
|
@ -122,22 +122,6 @@ def comma_space_split(s):
|
||||||
s = [x for x in s if x]
|
s = [x for x in s if x]
|
||||||
return s
|
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):
|
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,
|
Given the w+h of the image and the w+h of the frame,
|
||||||
|
|
|
@ -9,6 +9,7 @@ from voussoirkit import cacheclass
|
||||||
|
|
||||||
from .. import common
|
from .. import common
|
||||||
from .. import decorators
|
from .. import decorators
|
||||||
|
from .. import helpers
|
||||||
from .. import jsonify
|
from .. import jsonify
|
||||||
|
|
||||||
site = common.site
|
site = common.site
|
||||||
|
@ -396,7 +397,7 @@ def get_search_core():
|
||||||
if len(photos) == limit:
|
if len(photos) == limit:
|
||||||
next_params = original_params.copy()
|
next_params = original_params.copy()
|
||||||
next_params['offset'] = offset + limit
|
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
|
next_page_url = '/search' + next_params
|
||||||
else:
|
else:
|
||||||
next_page_url = None
|
next_page_url = None
|
||||||
|
@ -404,7 +405,7 @@ def get_search_core():
|
||||||
if offset > 0:
|
if offset > 0:
|
||||||
prev_params = original_params.copy()
|
prev_params = original_params.copy()
|
||||||
prev_params['offset'] = max(0, offset - limit)
|
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
|
prev_page_url = '/search' + prev_params
|
||||||
else:
|
else:
|
||||||
prev_page_url = None
|
prev_page_url = None
|
||||||
|
|
15
frontends/etiquette_flask/etiquette_flask/helpers.py
Normal file
15
frontends/etiquette_flask/etiquette_flask/helpers.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue