forms.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:jenkins-panel 作者: nikitinsm 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号