Projet

Général

Profil

0001-mdel_ddpacs-handle-xs-double-as-decimal-strings-3982.patch

Benjamin Dauvergne, 13 février 2020 14:12

Télécharger (2,08 ko)

Voir les différences:

Subject: [PATCH] mdel_ddpacs: handle xs:double as decimal strings (#39820)

 passerelle/apps/mdel_ddpacs/models.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
passerelle/apps/mdel_ddpacs/models.py
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18 18
from __future__ import unicode_literals
19
from decimal import Decimal
19 20

  
20 21
from django.db import models
21 22
from django.utils.translation import ugettext_lazy as _
......
31 32
class DDPACSSchema(JSONSchemaFromXMLSchema):
32 33
    type_map = {
33 34
        'CiviliteType': 'civilite',
35
        '{http://www.w3.org/2001/XMLSchema}double': 'double',
34 36
    }
35 37
    civilite_map = {
36 38
        'Monsieur': 'M',
......
44 46
            'enum': ['Madame', 'Monsieur'],
45 47
        }
46 48

  
49
    @classmethod
50
    def schema_double(cls):
51
        return {
52
            'anyOf': [
53
                {
54
                    'type': 'number'
55
                },
56
                {
57
                    'type': 'string',
58
                    'pattern': r'[0-9]*(\.[0-9]*)?',
59
                }
60
            ]
61
        }
62

  
47 63
    def encode_civilite(self, obj):
48 64
        try:
49 65
            return self.civilite_map[obj]
......
56 72
                return xmlschema.ElementData(tag=data.tag, text=key, content=data.content, attributes=data.attributes)
57 73
        raise xmlschema.XMLSchemaValidationError(self, data, reason='civilite invalide %s')
58 74

  
75
    def decode_double(self, data):
76
        return data._replace(text=str(data.text))
77

  
78
    def encode_double(self, obj):
79
        return float(obj)
80

  
59 81

  
60 82
class Resource(abstract.Resource):
61 83
    category = _('Civil Status Connectors')
62
-