mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add some helper functions
This commit is contained in:
parent
2191b7f719
commit
590dedce13
@ -4,6 +4,15 @@ from wsgiref.util import FileWrapper
|
||||
from django.http import StreamingHttpResponse
|
||||
|
||||
|
||||
def str2bool(text, test=True):
|
||||
""" Test if a string 'looks' like a boolean value
|
||||
"""
|
||||
if test:
|
||||
return str(text).lower() in ['1', 'y', 'yes', 't', 'true', 'ok', ]
|
||||
else:
|
||||
return str(text).lower() in ['0', 'n', 'no', 'none', 'f', 'false',]
|
||||
|
||||
|
||||
def WrapWithQuotes(text):
|
||||
# TODO - Make this better
|
||||
if not text.startswith('"'):
|
||||
|
@ -183,7 +183,7 @@ def FilterChildren(queryset, parent):
|
||||
|
||||
if not parent:
|
||||
return queryset
|
||||
elif str(parent).lower() in ['none', 'false', 'null', 'top', '0']:
|
||||
elif str2bool(parent, False):
|
||||
return queryset.filter(parent=None)
|
||||
else:
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user