memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
This commit is contained in:
parent
20c94f1fbc
commit
ac59d061f4
1 changed files with 80 additions and 11 deletions
|
|
@ -48,9 +48,9 @@ class Params(object):
|
|||
<category name="Connection" label="%(category_connection)s">
|
||||
<param name="JabberID" value="name@example.org/SàT" type="string" />
|
||||
<param name="Password" value="" type="password" />
|
||||
<param name="Priority" value="50" type="string" />
|
||||
<param name="Priority" value="50" type="int" min="-128" max="127"/>
|
||||
<param name="%(force_server_param)s" value="" type="string" />
|
||||
<param name="%(force_port_param)s" value="" type="string" />
|
||||
<param name="%(force_port_param)s" value="" type="int" min="80" max="65535" />
|
||||
<param name="NewAccount" label="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/>
|
||||
<param name="autoconnect" label="%(label_autoconnect)s" value="true" type="bool" />
|
||||
<param name="autodisconnect" label="%(label_autodisconnect)s" value="false" type="bool" />
|
||||
|
|
@ -331,6 +331,8 @@ class Params(object):
|
|||
value_to_use = value if value is not None else node.getAttribute(attr) # we use value (user defined) if it exist, else we use node's default value
|
||||
if node.getAttribute('type') == 'bool':
|
||||
return value_to_use.lower() not in ('false', '0', 'no')
|
||||
if node.getAttribute('type') == 'int':
|
||||
return int(value_to_use)
|
||||
elif node.getAttribute('type') == 'list':
|
||||
options = [option for option in node.childNodes if option.nodeName == 'option']
|
||||
values = [option.getAttribute('value') for option in options]
|
||||
|
|
@ -398,6 +400,8 @@ class Params(object):
|
|||
""" convert result to string, according to its type """
|
||||
if isinstance(result, bool):
|
||||
return "true" if result else "false"
|
||||
elif isinstance(result, int):
|
||||
return str(result)
|
||||
return result
|
||||
|
||||
def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE):
|
||||
|
|
@ -729,7 +733,7 @@ class Params(object):
|
|||
node = self._getParamNode(name, category, '@ALL@')
|
||||
if not node:
|
||||
log.error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
|
||||
% {'category': category, 'name': name})
|
||||
% {'category': category, 'name': name})
|
||||
return defer.succeed(None)
|
||||
|
||||
if not self.checkSecurityLimit(node[1], security_limit):
|
||||
|
|
@ -738,6 +742,21 @@ class Params(object):
|
|||
return defer.succeed(None)
|
||||
|
||||
type_ = node[1].getAttribute("type")
|
||||
if type_ == 'int':
|
||||
if not value: # replace with the default value (which might also be '')
|
||||
value = node[1].getAttribute("value")
|
||||
else:
|
||||
try:
|
||||
int(value)
|
||||
except ValueError:
|
||||
log.debug(_("Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value"
|
||||
% {'param': name, 'cat': category}))
|
||||
return defer.succeed(None)
|
||||
if node[1].hasAttribute("min"):
|
||||
value = str(max(int(value), int(node[1].getAttribute("min"))))
|
||||
if node[1].hasAttribute("max"):
|
||||
value = str(min(int(value), int(node[1].getAttribute("max"))))
|
||||
|
||||
log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") %
|
||||
{'category': category, 'name': name, 'value': value if type_ != 'password' else '********'})
|
||||
|
||||
|
|
@ -789,7 +808,7 @@ class Params(object):
|
|||
|
||||
TODO: using during the dev but not anymore... remove if not needed
|
||||
|
||||
@param attr_type (str): the attribute type (string, text, password, bool, button, list)
|
||||
@param attr_type (str): the attribute type (string, text, password, bool, int, button, list)
|
||||
@param node_type (str): keyword for filtering:
|
||||
@ALL@ search everywhere
|
||||
@GENERAL@ only search in general type
|
||||
|
|
|
|||
Loading…
Reference in a new issue