mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve str2bool to validate checkbox return values
- A checked checkbox returns 'on' :|
This commit is contained in:
parent
2e5b0bc961
commit
19854b4709
@ -104,9 +104,9 @@ def str2bool(text, test=True):
|
|||||||
True if the text looks like the selected boolean value
|
True if the text looks like the selected boolean value
|
||||||
"""
|
"""
|
||||||
if test:
|
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:
|
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='"'):
|
def WrapWithQuotes(text, quote='"'):
|
||||||
|
@ -192,7 +192,7 @@ class PartCreate(AjaxCreateView):
|
|||||||
context['matches'] = matches
|
context['matches'] = matches
|
||||||
|
|
||||||
# Check if the user has checked the 'confirm_creation' input
|
# 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:
|
if not confirmed:
|
||||||
form.fields['confirm_creation'].widget = CheckboxInput()
|
form.fields['confirm_creation'].widget = CheckboxInput()
|
||||||
|
Loading…
Reference in New Issue
Block a user