From 590dedce13e04a91d13a3ce4f096f8a334c46ae4 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 23:08:33 +1000 Subject: [PATCH] Add some helper functions --- InvenTree/InvenTree/helpers.py | 9 +++++++++ InvenTree/InvenTree/models.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index ba3f3525d5..872c4fe458 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -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('"'): diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index 4c25be2fe6..b7468cd7cb 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -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: