(self)
| 805 | return response |
| 806 | |
| 807 | def export(self): |
| 808 | try: |
| 809 | self.is_valid() |
| 810 | id = self.data.get("id") |
| 811 | tool = QuerySet(Tool).filter(id=id).first() |
| 812 | tool_dict = ToolExportModelSerializer(tool).data |
| 813 | # 如果是SKILL类型的工具,校验文件是否存在 |
| 814 | if tool.tool_type == ToolType.SKILL: |
| 815 | skill_file = QuerySet(File).filter(id=tool.code).first() |
| 816 | if skill_file: |
| 817 | tool_dict["code"] = base64.b64encode(skill_file.get_bytes()).decode("utf-8") |
| 818 | if tool.tool_type == ToolType.WORKFLOW: |
| 819 | workflow = QuerySet(ToolWorkflow).filter(tool_id=tool.id).first() |
| 820 | if workflow: |
| 821 | tool_dict["work_flow"] = workflow.work_flow |
| 822 | tool_dict["tool_list"] = self.get_child_tool_list(workflow.work_flow, []) |
| 823 | mk_instance = ToolInstance(tool_dict, "v2") |
| 824 | tool_pickle = pickle.dumps(mk_instance) |
| 825 | response = HttpResponse(content_type="text/plain", content=tool_pickle) |
| 826 | response["Content-Disposition"] = f'attachment; filename="{tool.name}.tool"' |
| 827 | return response |
| 828 | except Exception as e: |
| 829 | return result.error(str(e), response_status=status.HTTP_500_INTERNAL_SERVER_ERROR) |
| 830 | |
| 831 | class Pylint(serializers.Serializer): |
| 832 | def run(self, instance, is_valid=True): |
no test coverage detected