# HG changeset patch # User Goffi # Date 1578054045 -3600 # Node ID eec0c25c796bc4ad8f759c32ff4cac1c9d7f07b3 # Parent 118d91c932a747461180b381f62a8bb133e19332 core (memory/params): new "makeOptions" method to easily create options XML from a dict diff -r 118d91c932a7 -r eec0c25c796b sat/memory/params.py --- a/sat/memory/params.py Mon Dec 30 20:59:46 2019 +0100 +++ b/sat/memory/params.py Fri Jan 03 13:20:45 2020 +0100 @@ -31,6 +31,7 @@ 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 @@ 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'