diff --git a/sat/memory/params.py b/sat/memory/params.py index d08c6779..3714e6f4 100644 --- a/sat/memory/params.py +++ b/sat/memory/params.py @@ -31,6 +31,7 @@ from twisted.python.failure import Failure from twisted.words.xish import domish from twisted.words.protocols.jabber import jid from sat.tools.xml_tools import paramsXML2XMLUI, getText +from xml.sax.saxutils import quoteattr # TODO: params should be rewritten using Twisted directly instead of minidom # general params should be linked to sat.conf and kept synchronised @@ -1132,3 +1133,29 @@ class Params(object): if not app or not node.hasAttribute("app"): return True return node.getAttribute("app") == app + + +def makeOptions(options, selected=None): + """Create option XML form dictionary + + @param options(dict): option's name => option's label map + @param selected(None, str): value of selected option + None to use first value + @return (str): XML to use in parameters + """ + str_list = [] + if selected is None: + selected = next(iter(options.keys())) + selected_found = False + for value, label in options.items(): + if value == selected: + selected = 'selected="true"' + selected_found = True + else: + selected = '' + str_list.append( + f'