mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
development: [PyOne] prevent dropping empty values in template
This commit is contained in:
parent
b2d8fe2a3f
commit
787818dfbd
@ -1,6 +1,6 @@
|
||||
# Copyright 2018 www.privaz.io Valletech AB
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems
|
||||
#
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -46,7 +46,8 @@ def cast2one(param):
|
||||
root = list(param.values())[0]
|
||||
if isinstance(root, dict):
|
||||
# We return this dictionary as XML
|
||||
return dicttoxml.dicttoxml(param, root=False, attr_type=False).decode('utf8')
|
||||
return dicttoxml.dicttoxml(param, root=False, attr_type=False,
|
||||
cdata=True).decode('utf8')
|
||||
else:
|
||||
# We return this dictionary as attribute=value vector
|
||||
ret = u""
|
||||
@ -72,6 +73,14 @@ def one2dict(element):
|
||||
return element._root
|
||||
|
||||
|
||||
def none2emptystr(d):
|
||||
for k,v in d.items():
|
||||
if type(v) == OrderedDict:
|
||||
none2emptystr(v)
|
||||
elif v == None:
|
||||
d[k] = ""
|
||||
|
||||
|
||||
def child2dict(element):
|
||||
'''
|
||||
Creates a dictionary from the documentTree obtained from a binding Element.
|
||||
@ -93,6 +102,9 @@ def child2dict(element):
|
||||
if ret[tagName] == None:
|
||||
ret[tagName] = OrderedDict()
|
||||
|
||||
# Replace 'None' values returned by xmltodict by ""
|
||||
none2emptystr(ret)
|
||||
|
||||
# return the contents dictionary, but save a reference
|
||||
ret[tagName]._root = ret
|
||||
return ret[tagName]
|
||||
|
Loading…
x
Reference in New Issue
Block a user