From 38b8a0034489302b75bdee0ca7ae2b9be668f436 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 5 Apr 2019 10:59:43 +0100 Subject: [PATCH] Fix boolean columns --- app/commands.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/commands.py b/app/commands.py index 413b229be..945cdba42 100644 --- a/app/commands.py +++ b/app/commands.py @@ -694,14 +694,22 @@ def populate_organisations_from_file(file_name): # and user_to_organisation will be cleared before running this command. # Ignoring duplicates allows us to run the command again with the same file or same file with new rows. with open(file_name, 'r') as f: + def boolean_or_none(field): + if field == '1': + return True + elif field == '0': + return False + elif field == '': + return None + for line in itertools.islice(f, 1, None): columns = line.split('|') print(columns) data = { 'name': columns[0], 'active': True, - 'agreement_signed': True if columns[3] == 'TRUE' else False, - 'crown': True if columns[2] == 'TRUE' else False, + 'agreement_signed': boolean_or_none(columns[3]), + 'crown': boolean_or_none(columns[2]), 'organisation_type': columns[1].lower() } org = Organisation(**data)