fix(cookieManager): 修复新增/编辑页面点击保存无响应
原因1:cookie 四个页面(add/edit x user/site)缺少 {% include 'system/common/footer.html' %},
导致 layui.js/pear.js 未加载,layui.use 报错,提交按钮的 submit 事件从未绑定。
原因2:expiry 字段为空字符串时直接写入 DateTime 列,SQLite 抛
TypeError(SQLite DateTime type only accepts Python datetime and date objects)。
新增 _parse_expiry 辅助函数:空值转 None,非空按格式解析为 datetime。
已用 Playwright 真机验证:新增/编辑均返回 200 且数据落库。
This commit is contained in:
@@ -4,6 +4,7 @@ Cookie管理 - 登录网站视图
|
||||
URL: /system/cookie-site
|
||||
"""
|
||||
import os
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, render_template, request
|
||||
from flask_login import current_user
|
||||
|
||||
@@ -22,6 +23,19 @@ bp = Blueprint('cookie_site', __name__,
|
||||
template_folder=os.path.join(dir_path, '..', 'templates'))
|
||||
|
||||
|
||||
def _parse_expiry(raw):
|
||||
"""过期时间:空值转 None;非空字符串按常见格式解析为 datetime;解析失败返回 None。"""
|
||||
if not raw or not str(raw).strip():
|
||||
return None
|
||||
raw = str(raw).strip()
|
||||
for fmt in ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', '%Y-%m-%d'):
|
||||
try:
|
||||
return datetime.strptime(raw, fmt)
|
||||
except ValueError:
|
||||
continue
|
||||
return None
|
||||
|
||||
|
||||
@bp.get('/')
|
||||
@authorize("system:cookie-site:main")
|
||||
def main():
|
||||
@@ -72,7 +86,7 @@ def save():
|
||||
cookie_value=cookie_value,
|
||||
domain=str_escape(req_json.get('domain')),
|
||||
path=str_escape(req_json.get('path')) or '/',
|
||||
expiry=req_json.get('expiry'),
|
||||
expiry=_parse_expiry(req_json.get('expiry')),
|
||||
secure=int(req_json.get('secure') or 0),
|
||||
http_only=int(req_json.get('http_only') or 0),
|
||||
enable=int(req_json.get('enable') or 1),
|
||||
@@ -115,7 +129,7 @@ def update():
|
||||
obj.cookie_value = cookie_value
|
||||
obj.domain = str_escape(req_json.get('domain'))
|
||||
obj.path = str_escape(req_json.get('path')) or '/'
|
||||
obj.expiry = req_json.get('expiry')
|
||||
obj.expiry = _parse_expiry(req_json.get('expiry'))
|
||||
obj.secure = int(req_json.get('secure') or 0)
|
||||
obj.http_only = int(req_json.get('http_only') or 0)
|
||||
obj.enable = int(req_json.get('enable') or 1)
|
||||
|
||||
Reference in New Issue
Block a user