优化update_local_app
This commit is contained in:
parent
eb390e6853
commit
b804787f40
@ -112,7 +112,7 @@ def get_local_app(name):
|
|||||||
"""获取本地应用详情"""
|
"""获取本地应用详情"""
|
||||||
|
|
||||||
if not jingrow.db.exists("Local App", name):
|
if not jingrow.db.exists("Local App", name):
|
||||||
jingrow.throw("Local App not found")
|
return {"success": False, "message": "应用不存在"}
|
||||||
|
|
||||||
app = jingrow.get_pg("Local App", name)
|
app = jingrow.get_pg("Local App", name)
|
||||||
|
|
||||||
@ -177,21 +177,31 @@ def update_local_app(name, app_data):
|
|||||||
"""更新本地应用"""
|
"""更新本地应用"""
|
||||||
|
|
||||||
if not jingrow.db.exists("Local App", name):
|
if not jingrow.db.exists("Local App", name):
|
||||||
jingrow.throw("Local App not found")
|
return {"success": False, "message": "应用不存在"}
|
||||||
|
|
||||||
app = jingrow.get_pg("Local App", name)
|
app = jingrow.get_pg("Local App", name)
|
||||||
|
|
||||||
|
# 解析 JSON 数据
|
||||||
if isinstance(app_data, str):
|
if isinstance(app_data, str):
|
||||||
import json
|
try:
|
||||||
app_data = json.loads(app_data)
|
import json
|
||||||
|
app_data = json.loads(app_data)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
return {"success": False, "message": "JSON 数据格式错误"}
|
||||||
|
|
||||||
# 更新字段
|
# 更新字段
|
||||||
|
updated_fields = []
|
||||||
for field, value in app_data.items():
|
for field, value in app_data.items():
|
||||||
if hasattr(app, field):
|
if hasattr(app, field):
|
||||||
setattr(app, field, value)
|
setattr(app, field, value)
|
||||||
|
updated_fields.append(field)
|
||||||
|
|
||||||
|
# 检查是否有字段被更新
|
||||||
|
if not updated_fields:
|
||||||
|
return {"success": False, "message": "没有有效的字段被更新"}
|
||||||
|
|
||||||
app.save()
|
app.save()
|
||||||
return app.name
|
return {"success": True, "name": app.name, "updated_fields": updated_fields, "message": "应用更新成功"}
|
||||||
|
|
||||||
|
|
||||||
@dashboard_whitelist()
|
@dashboard_whitelist()
|
||||||
@ -199,12 +209,12 @@ def delete_local_app(name):
|
|||||||
"""删除本地应用"""
|
"""删除本地应用"""
|
||||||
|
|
||||||
if not jingrow.db.exists("Local App", name):
|
if not jingrow.db.exists("Local App", name):
|
||||||
jingrow.throw("Local App not found")
|
return {"success": False, "message": "应用不存在"}
|
||||||
|
|
||||||
app = jingrow.get_pg("Local App", name)
|
app = jingrow.get_pg("Local App", name)
|
||||||
app.delete()
|
app.delete()
|
||||||
|
|
||||||
return "Local App deleted successfully"
|
return {"success": True, "message": "应用删除成功"}
|
||||||
|
|
||||||
|
|
||||||
@jingrow.whitelist(allow_guest=True)
|
@jingrow.whitelist(allow_guest=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user