misc: add variant deserialization method for dates/phones
This commit is contained in:
parent
d6212c93e1
commit
828075ae23
|
@ -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,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue