Add some helper functions

This commit is contained in:
Oliver Walters 2019-04-18 23:08:33 +10:00
parent 2191b7f719
commit 590dedce13
2 changed files with 10 additions and 1 deletions

View File

@ -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('"'):

View File

@ -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: