@@ -105,32 +105,18 @@ def validate(value):
105105 raise ValidateException (err )
106106
107107
108- def serialize (value ):
108+ def _siam_serialize (value ):
109109
110110 validate (value )
111111
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-
127112 intercettazioni = etree .Element ('Intercettazioni' )
128113 (etree .SubElement (intercettazioni , 'ID' )).text = str (value ['id' ]) if 'id' in value else '1'
129114 (etree .SubElement (intercettazioni , 'Beneficiario' )).text = unicode (value ['beneficiario' ].strip ('IT' ))
130115 (etree .SubElement (intercettazioni , 'TipoPagamento' )).text = value ['tipopagamento' ]
131116 (etree .SubElement (intercettazioni , 'EntePagante' )).text = value ['entepagante' ]
132117 (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 ''
134120 (etree .SubElement (intercettazioni , 'NumeroModello37' )).text = \
135121 value ['numeromodello37' ] if 'numeromodello37' in value else None
136122 (etree .SubElement (intercettazioni , 'Registro' )).text = value ['registro' ]
@@ -150,7 +136,32 @@ def serialize(value):
150136 (etree .SubElement (intercettazioni , 'NomeMagistrato' )).text = unicode (value ['nomemagistrato' ])
151137 (etree .SubElement (intercettazioni , 'TipoIntercettazione' )).text = value ['tipointercettazione' ]
152138
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 ))
154165
155166 if lxml :
156167 return etree .tostring (siammxml , xml_declaration = True , encoding = 'UTF-8' , pretty_print = True )
0 commit comments