changeset 1747:40b7f18ac704

memory (params): fixes loading user value and building params XML for jids_list type
author souliane <souliane@mailoo.org>
date Tue, 15 Dec 2015 17:43:36 +0100
parents 0dfabe746ec4
children 3a6cd1c14974
files src/memory/params.py
diffstat 1 files changed, 23 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/params.py	Tue Dec 15 17:03:30 2015 +0100
+++ b/src/memory/params.py	Tue Dec 15 17:43:36 2015 +0100
@@ -371,23 +371,25 @@
             if node.getAttribute('type') == 'int':
                 return int(value_to_use)
             elif node.getAttribute('type') == 'list':
-                assert not value_to_use  # only accept <option selected...> and not <param value...>
-                options = [option for option in node.childNodes if option.nodeName == 'option']
-                selected = [option for option in options if option.getAttribute('selected') == 'true']
-                cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name')
-                if len(selected) == 1:
-                    value_to_use = selected[0].getAttribute('value')
-                    log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") %
-                             {'cat': cat, 'param': param, 'value': value_to_use})
-                    return value_to_use
-                if len(selected) == 0:
-                    log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param})
-                else:
-                    log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param})
-                raise exceptions.DataError
+                if not value_to_use:  # no user defined value, take default value from the XML
+                    options = [option for option in node.childNodes if option.nodeName == 'option']
+                    selected = [option for option in options if option.getAttribute('selected') == 'true']
+                    cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name')
+                    if len(selected) == 1:
+                        value_to_use = selected[0].getAttribute('value')
+                        log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") %
+                                 {'cat': cat, 'param': param, 'value': value_to_use})
+                        return value_to_use
+                    if len(selected) == 0:
+                        log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param})
+                    else:
+                        log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param})
+                    raise exceptions.DataError
             elif node.getAttribute('type') == 'jids_list':
-                assert not value_to_use  # only accept <jid>...</jid> and not <param value...>
-                jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")]
+                if value_to_use:
+                    jids = value_to_use.split('\t')  # FIXME: it's not good to use tabs as separator !
+                else:  # no user defined value, take default value from the XML
+                    jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")]
                 to_delete = []
                 for idx, value in enumerate(jids):
                     try:
@@ -689,15 +691,17 @@
                                         except NotFoundErr:
                                             pass
                             elif dest_params[name].getAttribute('type') == 'jids_list':
-                                jids = [getText(jid_) for jid_ in dest_params[name].getElementsByTagName("jid")]
-                                for jid_ in jids:
+                                jids = profile_value.split('\t')
+                                for jid_elt in dest_params[name].getElementsByTagName("jid"):
+                                    dest_params[name].removeChild(jid_elt)  # remove all default
+                                for jid_ in jids:  # rebuilt the children with use values
                                     try:
                                         jid.JID(jid_)
                                     except (RuntimeError, jid.InvalidFormat, AttributeError):
                                         log.warning(u"Incorrect jid value found in jids list: [{}]".format(jid_))
                                     else:
                                         jid_elt = prof_xml.createElement('jid')
-                                        jid_elt.appendChild(prof_xml.createTextNode())
+                                        jid_elt.appendChild(prof_xml.createTextNode(jid_))
                                         dest_params[name].appendChild(jid_elt)
                             else:
                                 dest_params[name].setAttribute('value', profile_value)