simplify tiramisu dict format
This commit is contained in:
@ -24,7 +24,7 @@ from .i18n import _
|
||||
from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \
|
||||
FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES, EXPIRATION_TIME
|
||||
from .config import KernelConfig, SubConfig, KernelGroupConfig, KernelMetaConfig, KernelMixConfig
|
||||
from .option import ChoiceOption, OptionDescription
|
||||
from .option import ChoiceOption, RegexpOption, OptionDescription
|
||||
from .todict import TiramisuDict
|
||||
|
||||
|
||||
@ -265,6 +265,19 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
|
||||
option = self._option_bag.option
|
||||
return option.impl_get_callback()
|
||||
|
||||
def pattern(self) -> str:
|
||||
option = self._option_bag.option
|
||||
type = option.get_type()
|
||||
if isinstance(option, RegexpOption):
|
||||
return option._regexp.pattern
|
||||
if type == 'integer':
|
||||
return r'^[0-9]+$'
|
||||
if type == 'domainname':
|
||||
return option.impl_get_extra('_domain_re').pattern
|
||||
if type in ['ip', 'network', 'netmask']:
|
||||
#FIXME only from 0.0.0.0 to 255.255.255.255
|
||||
return r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
|
||||
|
||||
|
||||
class TiramisuOptionOption(CommonTiramisuOption):
|
||||
"""Manage option"""
|
||||
|
@ -398,13 +398,13 @@ class TiramisuDict:
|
||||
if order is not None:
|
||||
order.append(path)
|
||||
if childapi.option.isoptiondescription():
|
||||
web_type = 'optiondescription'
|
||||
if childapi_option.isleadership():
|
||||
type_ = 'array'
|
||||
else:
|
||||
type_ = 'object'
|
||||
if schema is not None:
|
||||
schema[path] = {'name': path,
|
||||
'properties': OrderedDict(),
|
||||
schema[path] = {'properties': OrderedDict(),
|
||||
'type': type_}
|
||||
subschema = schema[path]['properties']
|
||||
else:
|
||||
@ -425,22 +425,22 @@ class TiramisuDict:
|
||||
web_type = 'symlink'
|
||||
else:
|
||||
web_type = childapi_option.type()
|
||||
value = childapi.option.default()
|
||||
if value not in [[], None]:
|
||||
has_value = True
|
||||
else:
|
||||
value = None
|
||||
has_value = False
|
||||
|
||||
is_multi = childapi_option.ismulti()
|
||||
if is_multi:
|
||||
default = childapi_option.defaultmulti()
|
||||
if default not in [None, []]:
|
||||
value = childapi.option.default()
|
||||
if value not in [[], None]:
|
||||
has_value = True
|
||||
else:
|
||||
value = None
|
||||
has_value = False
|
||||
|
||||
is_multi = childapi_option.ismulti()
|
||||
if is_multi:
|
||||
default = childapi_option.defaultmulti()
|
||||
if default not in [None, []]:
|
||||
has_value = True
|
||||
else:
|
||||
default = None
|
||||
else:
|
||||
default = None
|
||||
else:
|
||||
default = None
|
||||
|
||||
if schema is not None:
|
||||
self.gen_schema(schema,
|
||||
@ -461,7 +461,8 @@ class TiramisuDict:
|
||||
childtype,
|
||||
has_value)
|
||||
if schema is not None:
|
||||
schema[path]['title'] = childapi_option.doc()
|
||||
if web_type != 'symlink':
|
||||
schema[path]['title'] = childapi_option.doc()
|
||||
self.add_help(schema[path],
|
||||
childapi)
|
||||
if init and form is not None:
|
||||
@ -482,8 +483,7 @@ class TiramisuDict:
|
||||
default,
|
||||
is_multi,
|
||||
web_type):
|
||||
schema[path] = {'name': path,
|
||||
'type': web_type}
|
||||
schema[path] = {'type': web_type}
|
||||
if childapi_option.issymlinkoption():
|
||||
schema[path]['opt_path'] = childapi_option.get().impl_getopt().impl_getpath()
|
||||
else:
|
||||
@ -528,15 +528,9 @@ class TiramisuDict:
|
||||
obj_form['clearable'] = True
|
||||
if self.remotable == 'all' or childapi_option.has_dependency():
|
||||
obj_form['remote'] = True
|
||||
if web_type == 'integer':
|
||||
obj_form['allowedpattern'] = '[0-9]'
|
||||
if isinstance(child, RegexpOption):
|
||||
obj_form['pattern'] = child._regexp.pattern
|
||||
if web_type == 'domainname':
|
||||
obj_form['pattern'] = child.impl_get_extra('_domain_re').pattern
|
||||
if childtype in ['IPOption', 'NetworkOption', 'NetmaskOption']:
|
||||
#FIXME only from 0.0.0.0 to 255.255.255.255
|
||||
obj_form['pattern'] = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
|
||||
pattern = childapi_option.pattern()
|
||||
if pattern is not None:
|
||||
obj_form['pattern'] = pattern
|
||||
if childtype == 'FloatOption':
|
||||
obj_form['step'] = 'any'
|
||||
if childtype == 'PortOption':
|
||||
|
Reference in New Issue
Block a user