mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Extract string-to-bool logic into utils.py
This commit is contained in:
parent
d0a578c0fc
commit
7e0caa1e62
2 changed files with 25 additions and 5 deletions
|
|
@ -800,3 +800,13 @@ def path_with_format(request, format, extra_qs=None):
|
|||
elif request.query_string:
|
||||
path = "{}?{}".format(path, request.query_string)
|
||||
return path
|
||||
|
||||
|
||||
def value_as_boolean(value):
|
||||
if value.lower() not in ('on', 'off', 'true', 'false', '1', '0'):
|
||||
raise ValueAsBooleanError
|
||||
return value.lower() in ('on', 'true', '1')
|
||||
|
||||
|
||||
class ValueAsBooleanError(ValueError):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue