misc: add variant deserialization method for dates/phones

This commit is contained in:
Frédéric Péters 2021-01-18 11:25:32 +01:00
parent d6212c93e1
commit 828075ae23
1 changed files with 13 additions and 4 deletions

View File

@ -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,
},