Improve str2bool to validate checkbox return values

- A checked checkbox returns 'on' :|
This commit is contained in:
Oliver Walters 2019-05-11 18:06:17 +10:00
parent 2e5b0bc961
commit 19854b4709
2 changed files with 3 additions and 3 deletions

View File

@ -104,9 +104,9 @@ def str2bool(text, test=True):
True if the text looks like the selected boolean value
"""
if test:
return str(text).lower() in ['1', 'y', 'yes', 't', 'true', 'ok', ]
return str(text).lower() in ['1', 'y', 'yes', 't', 'true', 'ok', 'on', ]
else:
return str(text).lower() in ['0', 'n', 'no', 'none', 'f', 'false', ]
return str(text).lower() in ['0', 'n', 'no', 'none', 'f', 'false', 'off',]
def WrapWithQuotes(text, quote='"'):

View File

@ -192,7 +192,7 @@ class PartCreate(AjaxCreateView):
context['matches'] = matches
# Check if the user has checked the 'confirm_creation' input
confirmed = request.POST.get('confirm_creation', False)
confirmed = str2bool(request.POST.get('confirm_creation', False))
if not confirmed:
form.fields['confirm_creation'].widget = CheckboxInput()