mdel_ddpacs: handle xs:double as decimal strings (#39820)
This commit is contained in:
parent
c1dc255b60
commit
a1d08fb705
|
@ -16,6 +16,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from decimal import Decimal
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -31,6 +32,7 @@ from . import abstract
|
|||
class DDPACSSchema(JSONSchemaFromXMLSchema):
|
||||
type_map = {
|
||||
'CiviliteType': 'civilite',
|
||||
'{http://www.w3.org/2001/XMLSchema}double': 'double',
|
||||
}
|
||||
civilite_map = {
|
||||
'Monsieur': 'M',
|
||||
|
@ -44,6 +46,20 @@ class DDPACSSchema(JSONSchemaFromXMLSchema):
|
|||
'enum': ['Madame', 'Monsieur'],
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def schema_double(cls):
|
||||
return {
|
||||
'anyOf': [
|
||||
{
|
||||
'type': 'number'
|
||||
},
|
||||
{
|
||||
'type': 'string',
|
||||
'pattern': r'[0-9]*(\.[0-9]*)?',
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def encode_civilite(self, obj):
|
||||
try:
|
||||
return self.civilite_map[obj]
|
||||
|
@ -56,6 +72,12 @@ class DDPACSSchema(JSONSchemaFromXMLSchema):
|
|||
return xmlschema.ElementData(tag=data.tag, text=key, content=data.content, attributes=data.attributes)
|
||||
raise xmlschema.XMLSchemaValidationError(self, data, reason='civilite invalide %s')
|
||||
|
||||
def decode_double(self, data):
|
||||
return data._replace(text=str(data.text))
|
||||
|
||||
def encode_double(self, obj):
|
||||
return float(obj)
|
||||
|
||||
|
||||
class Resource(abstract.Resource):
|
||||
category = _('Civil Status Connectors')
|
||||
|
|
Loading…
Reference in New Issue