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):
|
def attribute_kinds(self):
|
||||||
from . import fields
|
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 [
|
return [
|
||||||
{
|
{
|
||||||
'label': _('National Register Number'),
|
'label': _('National Register Number'),
|
||||||
|
@ -85,14 +94,14 @@ class Plugin(object):
|
||||||
{
|
{
|
||||||
'label': _('Date'),
|
'label': _('Date'),
|
||||||
'serialize': json.dumps,
|
'serialize': json.dumps,
|
||||||
'deserialize': json.loads,
|
'deserialize': attribute_json_loads,
|
||||||
'name': 'date',
|
'name': 'date',
|
||||||
'field_class': fields.DateField,
|
'field_class': fields.DateField,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': _('Date'),
|
'label': _('Date'),
|
||||||
'serialize': json.dumps,
|
'serialize': json.dumps,
|
||||||
'deserialize': json.loads,
|
'deserialize': attribute_json_loads,
|
||||||
'name': 'fedict_date',
|
'name': 'fedict_date',
|
||||||
'field_class': fields.DateField,
|
'field_class': fields.DateField,
|
||||||
},
|
},
|
||||||
|
@ -113,14 +122,14 @@ class Plugin(object):
|
||||||
{
|
{
|
||||||
'label': _('Phone number'),
|
'label': _('Phone number'),
|
||||||
'serialize': json.dumps,
|
'serialize': json.dumps,
|
||||||
'deserialize': json.loads,
|
'deserialize': attribute_json_loads,
|
||||||
'name': 'phone',
|
'name': 'phone',
|
||||||
'field_class': fields.NumPhoneField,
|
'field_class': fields.NumPhoneField,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': _('Phone number'),
|
'label': _('Phone number'),
|
||||||
'serialize': json.dumps,
|
'serialize': json.dumps,
|
||||||
'deserialize': json.loads,
|
'deserialize': attribute_json_loads,
|
||||||
'name': 'fedict_phone',
|
'name': 'fedict_phone',
|
||||||
'field_class': fields.NumPhoneField,
|
'field_class': fields.NumPhoneField,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue