@@ -105,32 +105,18 @@ def validate(value):
105
105
raise ValidateException (err )
106
106
107
107
108
- def serialize (value ):
108
+ def _siam_serialize (value ):
109
109
110
110
validate (value )
111
111
112
- NSMAP = {'od' : 'urn:schemas-microsoft-com:officedata' ,
113
- 'xsi' : 'http://www.w3.org/2001/XMLSchema-instance' }
114
-
115
- #: lxml and ElementTree support, different namespace definition
116
- #: try find better solution
117
-
118
- if lxml :
119
- siammxml = etree .Element ('dataroot' , nsmap = NSMAP )
120
- siammxml .set ('{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation' ,'Intercettazioni.xsd' )
121
- else :
122
- siammxml = etree .Element ('dataroot' )
123
- siammxml .set ('xmlns:od' , 'urn:schemas-microsoft-com:officedata' )
124
- siammxml .set ('xmlns:xsi' , 'http://www.w3.org/2001/XMLSchema-instance' )
125
- siammxml .set ('xsi:noNamespaceSchemaLocation' , 'Intercettazioni.xsd' )
126
-
127
112
intercettazioni = etree .Element ('Intercettazioni' )
128
113
(etree .SubElement (intercettazioni , 'ID' )).text = str (value ['id' ]) if 'id' in value else '1'
129
114
(etree .SubElement (intercettazioni , 'Beneficiario' )).text = unicode (value ['beneficiario' ].strip ('IT' ))
130
115
(etree .SubElement (intercettazioni , 'TipoPagamento' )).text = value ['tipopagamento' ]
131
116
(etree .SubElement (intercettazioni , 'EntePagante' )).text = value ['entepagante' ]
132
117
(etree .SubElement (intercettazioni , 'NumeroFattura' )).text = value ['numerofattura' ]
133
- (etree .SubElement (intercettazioni , 'DataEmissioneProvv' )).text = ''
118
+ (etree .SubElement (intercettazioni , 'DataEmissioneProvv' )).text = \
119
+ "{:%Y-%m-%dT%H:%M:%S}" .format (value ['dataemissioneprovv' ]) if 'dataemissioneprovv' in value else ''
134
120
(etree .SubElement (intercettazioni , 'NumeroModello37' )).text = \
135
121
value ['numeromodello37' ] if 'numeromodello37' in value else None
136
122
(etree .SubElement (intercettazioni , 'Registro' )).text = value ['registro' ]
@@ -150,7 +136,32 @@ def serialize(value):
150
136
(etree .SubElement (intercettazioni , 'NomeMagistrato' )).text = unicode (value ['nomemagistrato' ])
151
137
(etree .SubElement (intercettazioni , 'TipoIntercettazione' )).text = value ['tipointercettazione' ]
152
138
153
- siammxml .append (intercettazioni )
139
+ return intercettazioni
140
+
141
+
142
+
143
+ def serialize (value ):
144
+
145
+ NSMAP = {'od' : 'urn:schemas-microsoft-com:officedata' ,
146
+ 'xsi' : 'http://www.w3.org/2001/XMLSchema-instance' }
147
+
148
+ #: lxml and ElementTree support, different namespace definition
149
+ #: try find better solution
150
+
151
+ if lxml :
152
+ siammxml = etree .Element ('dataroot' , nsmap = NSMAP )
153
+ siammxml .set ('{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation' ,'Intercettazioni.xsd' )
154
+ else :
155
+ siammxml = etree .Element ('dataroot' )
156
+ siammxml .set ('xmlns:od' , 'urn:schemas-microsoft-com:officedata' )
157
+ siammxml .set ('xmlns:xsi' , 'http://www.w3.org/2001/XMLSchema-instance' )
158
+ siammxml .set ('xsi:noNamespaceSchemaLocation' , 'Intercettazioni.xsd' )
159
+
160
+ if isinstance (value , (list , tuple )):
161
+ for interc in value :
162
+ siammxml .append (_siam_serialize (interc ))
163
+ else :
164
+ siammxml .append (_siam_serialize (value ))
154
165
155
166
if lxml :
156
167
return etree .tostring (siammxml , xml_declaration = True , encoding = 'UTF-8' , pretty_print = True )
0 commit comments