mdel_ddpacs: handle xs:double as decimal strings (#39820)

This commit is contained in:
Benjamin Dauvergne 2020-02-13 14:11:16 +01:00 committed by Emmanuel Cazenave
parent c1dc255b60
commit a1d08fb705
1 changed files with 22 additions and 0 deletions

View File

@ -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')