def get_params_data(form_instance):
result = []
type_mapping = \
{ 'hudson.model.StringParameterDefinition': ('StringField', {})
, 'hudson.model.TextParameterDefinition': ('StringField', {})
, 'hudson.model.BooleanParameterDefinition': ('BooleanField', {})
, 'hudson.model.ChoiceParameterDefinition': ('SelectField', {})
}
xml_config = get_config(form_instance)
if not xml_config:
return result
tree = etree.fromstring(xml_config)
params_root = tree.findall('properties/hudson.model.ParametersDefinitionProperty/parameterDefinitions')
if params_root:
params = params_root[0].getchildren()
for param in params:
name = getattr(param.find('name'), 'text', None)
if not name:
continue
field_type, kwargs = type_mapping.get(param.tag, None)
if not type:
continue
choices = [(node.text, node.text) for node in param.findall('choices/a/string')]
if choices:
choices = [('', u'????????'), ] + choices
result.append\
( { 'name': name
, 'type': field_type
, 'description': getattr(param.find('description'), 'text', None)
, 'default': getattr(param.find('defaultValue'), 'text', None)
, 'choices': choices
, 'kwargs': kwargs
} )
return result
评论列表
文章目录