Exemple #1
0
    def alter_detail_data_to_serialize(self, request, data):
        bundle = data
        component = ComponentLibrary.get_component_class(bundle.data['code'])
        bundle.data['output'] = component.outputs_format()
        bundle.data['form'] = component.form
        bundle.data['desc'] = component.desc
        # 国际化
        name = bundle.data['name'].split('-')
        bundle.data['group_name'] = _(name[0])
        bundle.data['name'] = _(name[1])

        return data
Exemple #2
0
    def alter_list_data_to_serialize(self, request, data):
        for bundle in data['objects']:
            component = ComponentLibrary.get_component_class(
                bundle.data['code'])
            bundle.data['output'] = component.outputs_format()
            bundle.data['form'] = component.form
            bundle.data['desc'] = component.desc
            bundle.data['form_is_embedded'] = component.form_is_embedded()
            # 国际化
            name = bundle.data['name'].split('-')
            bundle.data['group_name'] = _(name[0])
            bundle.data['name'] = _(name[1])

        return data
Exemple #3
0
    def alter_detail_data_to_serialize(self, request, data):
        data = super(ComponentModelResource,
                     self).alter_detail_data_to_serialize(request, data)
        bundle = data
        component = ComponentLibrary.get_component_class(bundle.data['code'])
        bundle.data['output'] = component.outputs_format()
        bundle.data['form'] = component.form
        bundle.data['desc'] = component.desc
        bundle.data['form_is_embedded'] = component.form_is_embedded()
        # 国际化
        name = bundle.data['name'].split('-')
        bundle.data['group_name'] = _(name[0])
        bundle.data['name'] = _(name[1])

        return data
Exemple #4
0
    def schema_for_var(cls, var):
        source_type = var.get('source_type')
        if source_type not in cls.accept_var_type:
            return None

        source_tag = var.get('source_tag')
        try:
            code, tag = cls.decode_source_tag(source_tag)
        except Exception:
            logger.error(
                'error occurred when decode source_tag for {key}, var: {var}, error: {trace}'
                .format(key=var.get('key'),
                        var=var,
                        trace=traceback.format_exc()))
            return None

        if source_type == VAR_SOURCE_TYPE_INPUTS:
            component_cls = ComponentLibrary.get_component_class(
                component_code=code)
            # maybe custom var from subprocess
            if not component_cls:
                source_type = VAR_SOURCE_TYPE_CUSTOM
            else:
                schema = component_cls.get_input_schema(key=tag)

                ok, message = cls._schema_check(code=code,
                                                var=var,
                                                schema=schema,
                                                type='component')
                if not ok:
                    logger.error(message)
                    return None

                return schema.as_dict()

        if source_type == VAR_SOURCE_TYPE_CUSTOM:
            var_cls = VariableLibrary.get_var_class(code=code)
            schema = getattr(var_cls, 'schema', None)

            ok, message = cls._schema_check(code=code,
                                            var=var,
                                            schema=schema,
                                            type='variable')
            if not ok:
                logger.error(message)
                return None

            return schema.as_dict()
Exemple #5
0
def get_plugin_list(request, project_id):
    components = ComponentModel.objects.filter(status=True)

    data = []
    for comp_model in components:
        comp = ComponentLibrary.get_component_class(comp_model.code)
        data.append({
            'inputs': comp.inputs_format(),
            'outputs': comp.outputs_format(),
            'desc': comp.desc,
            'code': comp.code,
            'name': comp.name,
            'group_name': comp.group_name
        })

    return JsonResponse({'result': True, 'data': data})
Exemple #6
0
def get_plugin_detail(request, project_id):
    project_id = request.project.id
    code = request.GET.get("code")
    version = request.GET.get("version", "legacy")

    if not code:
        return {
            "result": False,
            "message": "parameter code need to be provided.",
            "code": err_code.VALIDATION_ERROR.code,
        }

    # 排除基于业务的插件,只支持公共插件
    exclude_component_codes = ProjectBasedComponent.objects.get_components_of_other_projects(
        project_id)
    try:
        component = ComponentModel.objects.exclude(
            code__in=exclude_component_codes).get(status=True,
                                                  code=code,
                                                  version=version)
    except ComponentModel.DoesNotExist:
        return {
            "result":
            False,
            "message":
            "can not find suitable component with code: {} and version: {}".
            format(code, version),
            "code":
            err_code.VALIDATION_ERROR.code,
        }

    component_info = ComponentLibrary.get_component_class(
        component.code, component.version)
    data = {
        "inputs": component_info.inputs_format(),
        "outputs": component_info.outputs_format(),
        "desc": component_info.desc,
        "code": component_info.code,
        "name": component_info.name,
        "group_name": component_info.group_name,
        "version": component_info.version,
        "form": component_info.form,
    }

    return {"result": True, "data": data, "code": err_code.SUCCESS.code}
Exemple #7
0
    def test_ignore_component(self):
        class IgnoreService(Service):
            def execute(self, data, parent_data):
                pass

        class IgnoreComponent(Component):
            name = u'ignore_service'
            bound_service = IgnoreService
            code = 'ignore_component'
            form = 'form path'

            def outputs_format(self):
                return {'result': bool, 'message': str}

            def clean_execute_data(self, context):
                return {}

        self.assertIsNone(
            ComponentLibrary.get_component_class('ignore_component'))
Exemple #8
0
    def alter_detail_data_to_serialize(self, request, data):
        bundle = super(ComponentModelResource, self).alter_detail_data_to_serialize(request, data)
        try:
            component = ComponentLibrary.get_component_class(bundle.data["code"], bundle.data["version"])
        except ComponentNotExistException:
            raise NotFound("Can not found {}({})".format(bundle.data["code"], bundle.data["version"]))
        bundle.data["output"] = component.outputs_format()
        bundle.data["form"] = component.form
        bundle.data["output_form"] = component.output_form
        bundle.data["desc"] = component.desc
        bundle.data["form_is_embedded"] = component.form_is_embedded()
        # 国际化
        name = bundle.data["name"].split("-")
        bundle.data["group_name"] = _(name[0])
        bundle.data["group_icon"] = component.group_icon
        bundle.data["name"] = _(name[1])
        # 被前端插件继承js的地址
        bundle.data["base"] = getattr(component, "base", None)

        return data
Exemple #9
0
def get_plugin_list(request, project_id):
    project_id = request.project.id

    exclude_component_codes = ProjectBasedComponent.objects.get_components_of_other_projects(project_id)
    components = ComponentModel.objects.filter(status=True).exclude(code__in=exclude_component_codes)

    data = []
    for comp_model in components:
        comp = ComponentLibrary.get_component_class(comp_model.code, comp_model.version)
        data.append(
            {
                "inputs": comp.inputs_format(),
                "outputs": comp.outputs_format(),
                "desc": comp.desc,
                "code": comp.code,
                "name": comp.name,
                "group_name": comp.group_name,
                "version": comp.version,
                "form": comp.form,
            }
        )

    return {"result": True, "data": data, "code": err_code.SUCCESS.code}
Exemple #10
0
 def group_icon(self):
     return ComponentLibrary.get_component_class(self.code).group_icon