fix: 修复函数库输入参数校验,搜索函数失败,编辑函数描述为空校验
This commit is contained in:
parent
d315c01133
commit
bee832994b
@ -9,12 +9,12 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from diskcache import Cache
|
from diskcache import Cache
|
||||||
|
|
||||||
|
from smartdoc.const import BASE_DIR
|
||||||
from smartdoc.const import PROJECT_DIR
|
from smartdoc.const import PROJECT_DIR
|
||||||
|
|
||||||
python_directory = sys.executable
|
python_directory = sys.executable
|
||||||
@ -81,10 +81,11 @@ except Exception as e:
|
|||||||
with open(exec_python_file, 'w') as file:
|
with open(exec_python_file, 'w') as file:
|
||||||
file.write(_code)
|
file.write(_code)
|
||||||
os.system(f"chown {self.user}:{self.user} {exec_python_file}")
|
os.system(f"chown {self.user}:{self.user} {exec_python_file}")
|
||||||
|
kwargs = {'cwd': BASE_DIR}
|
||||||
subprocess_result = subprocess.run(
|
subprocess_result = subprocess.run(
|
||||||
['su', '-c', python_directory + ' ' + exec_python_file, self.user],
|
['su', '-c', python_directory + ' ' + exec_python_file, self.user],
|
||||||
text=True,
|
text=True,
|
||||||
capture_output=True)
|
capture_output=True, **kwargs)
|
||||||
os.remove(exec_python_file)
|
os.remove(exec_python_file)
|
||||||
return subprocess_result
|
return subprocess_result
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import QuerySet
|
|
||||||
|
|
||||||
from common.db.sql_execute import select_one
|
from common.db.sql_execute import select_one
|
||||||
from common.mixins.app_model_mixin import AppModelMixin
|
from common.mixins.app_model_mixin import AppModelMixin
|
||||||
|
|||||||
@ -57,11 +57,14 @@ class DebugInstance(serializers.Serializer):
|
|||||||
|
|
||||||
|
|
||||||
class EditFunctionLib(serializers.Serializer):
|
class EditFunctionLib(serializers.Serializer):
|
||||||
name = serializers.CharField(required=False, error_messages=ErrMessage.char("函数名称"))
|
name = serializers.CharField(required=False, allow_null=True, allow_blank=True,
|
||||||
|
error_messages=ErrMessage.char("函数名称"))
|
||||||
|
|
||||||
desc = serializers.CharField(required=False, error_messages=ErrMessage.char("函数描述"))
|
desc = serializers.CharField(required=False, allow_null=True, allow_blank=True,
|
||||||
|
error_messages=ErrMessage.char("函数描述"))
|
||||||
|
|
||||||
code = serializers.CharField(required=False, error_messages=ErrMessage.char("函数内容"))
|
code = serializers.CharField(required=False, allow_null=True, allow_blank=True,
|
||||||
|
error_messages=ErrMessage.char("函数内容"))
|
||||||
|
|
||||||
input_field_list = FunctionLibInputField(required=False, many=True)
|
input_field_list = FunctionLibInputField(required=False, many=True)
|
||||||
|
|
||||||
@ -90,9 +93,9 @@ class FunctionLibSerializer(serializers.Serializer):
|
|||||||
def get_query_set(self):
|
def get_query_set(self):
|
||||||
query_set = QuerySet(FunctionLib).filter(user_id=self.data.get('user_id'))
|
query_set = QuerySet(FunctionLib).filter(user_id=self.data.get('user_id'))
|
||||||
if self.data.get('name') is not None:
|
if self.data.get('name') is not None:
|
||||||
query_set = query_set.filter(name=self.data.get('name'))
|
query_set = query_set.filter(name__contains=self.data.get('name'))
|
||||||
if self.data.get('desc') is not None:
|
if self.data.get('desc') is not None:
|
||||||
query_set = query_set.filter(name=self.data.get('desc'))
|
query_set = query_set.filter(desc__contains=self.data.get('desc'))
|
||||||
query_set = query_set.order_by("-create_time")
|
query_set = query_set.order_by("-create_time")
|
||||||
return query_set
|
return query_set
|
||||||
|
|
||||||
@ -158,9 +161,15 @@ class FunctionLibSerializer(serializers.Serializer):
|
|||||||
if _type == 'float':
|
if _type == 'float':
|
||||||
return float(value)
|
return float(value)
|
||||||
if _type == 'dict':
|
if _type == 'dict':
|
||||||
return json.loads(value)
|
v = json.loads(value)
|
||||||
|
if isinstance(v, dict):
|
||||||
|
return v
|
||||||
|
raise Exception("类型错误")
|
||||||
if _type == 'array':
|
if _type == 'array':
|
||||||
return json.loads(value)
|
v = json.loads(value)
|
||||||
|
if isinstance(v, list):
|
||||||
|
return v
|
||||||
|
raise Exception("类型错误")
|
||||||
return value
|
return value
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AppApiException(500, f'字段:{name}类型:{_type}值:{value}类型转换错误')
|
raise AppApiException(500, f'字段:{name}类型:{_type}值:{value}类型转换错误')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user