From 46fd9c1930fc34c3ad3c068322eea88b9d487cb0 Mon Sep 17 00:00:00 2001 From: Aly Badr Date: Fri, 22 Jun 2018 08:58:40 +0200 Subject: [PATCH] fix: fix rero/reroils-app#27 save patron without phones Signed-off-by: Aly Badr --- reroils_data/patrons/utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/reroils_data/patrons/utils.py b/reroils_data/patrons/utils.py index d4a2979..2cff55c 100644 --- a/reroils_data/patrons/utils.py +++ b/reroils_data/patrons/utils.py @@ -46,7 +46,7 @@ def save_patron(data, record_type, fetcher, minter, and attached to the patron. """ email = data.get('email') - data = staff_patron_fields(data) + data = clean_patron_fields(data) if email: find_user = datastore.find_user(email=email) if find_user is None: @@ -88,8 +88,16 @@ def save_patron(data, record_type, fetcher, minter, return _next, patron.persistent_identifier -def staff_patron_fields(data): - """Validate user fields based on user type (patorn or staff).""" +def clean_patron_fields(data): + """Clean patron fields. + + Remove empty fields and + validate user fields based on user type (patron/staff). + """ + for key, value in list(data.items()): + if not value or value == '': + del data[key] + if not data.get('is_patron'): if 'barcode' in data: del(data['barcode'])