diff --git a/src/authentic2_auth_fedict/__init__.py b/src/authentic2_auth_fedict/__init__.py index bb0fe58..d20ce62 100644 --- a/src/authentic2_auth_fedict/__init__.py +++ b/src/authentic2_auth_fedict/__init__.py @@ -74,6 +74,15 @@ class Plugin(object): def attribute_kinds(self): from . import fields + def attribute_json_loads(x): + if not x: + return x + try: + return json.loads(x) + except json.JSONDecodeError: + # "compatibility" with native date/phone kinds + return x + return [ { 'label': _('National Register Number'), @@ -85,14 +94,14 @@ class Plugin(object): { 'label': _('Date'), 'serialize': json.dumps, - 'deserialize': json.loads, + 'deserialize': attribute_json_loads, 'name': 'date', 'field_class': fields.DateField, }, { 'label': _('Date'), 'serialize': json.dumps, - 'deserialize': json.loads, + 'deserialize': attribute_json_loads, 'name': 'fedict_date', 'field_class': fields.DateField, }, @@ -113,14 +122,14 @@ class Plugin(object): { 'label': _('Phone number'), 'serialize': json.dumps, - 'deserialize': json.loads, + 'deserialize': attribute_json_loads, 'name': 'phone', 'field_class': fields.NumPhoneField, }, { 'label': _('Phone number'), 'serialize': json.dumps, - 'deserialize': json.loads, + 'deserialize': attribute_json_loads, 'name': 'fedict_phone', 'field_class': fields.NumPhoneField, },