bf67e0575f
- 信息架构重组: 周报精简为拜访+纪要两个Tab,工作计划/商机/要客独立为侧边栏「工作」分组下的独立页面 - 侧边栏分组: 汇总/工作/管理三层分组,仪表盘四卡可点击跳转 - 变更追踪(edit_log): 5张表新增JSONB edit_log列,POST创建/PUT diff自动记录,编辑弹窗变更时间轴,表格🕐编辑标记 - 图片预览增强: ImagePreview统一组件,支持适应页面/缩放/拖拽平移/滚轮缩放/键盘快捷键 - 修复客户导入500错误(errors变量未初始化) - 移除工作计划/商机/要客页面冗余编辑按钮 Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Edit log helpers for change tracking."""
|
|
import json
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
def compute_diff(old: dict, new: dict, exclude: set = None) -> dict:
|
|
"""Compare old and new values, return {field: [old, new]} for changed fields."""
|
|
if exclude is None:
|
|
exclude = {"edit_log", "updated_at", "created_at", "id"}
|
|
changes = {}
|
|
for key, new_val in new.items():
|
|
if key in exclude:
|
|
continue
|
|
old_val = old.get(key)
|
|
# Normalize for comparison
|
|
old_str = str(old_val) if old_val is not None else ""
|
|
new_str = str(new_val) if new_val is not None else ""
|
|
if old_str != new_str:
|
|
changes[key] = [old_str, new_str]
|
|
return changes
|
|
|
|
|
|
def append_entry(record, editor_name: str, changes: dict, reason: str = None):
|
|
"""Append an edit log entry to a record's edit_log JSON list."""
|
|
log = list(record.edit_log) if record.edit_log else []
|
|
entry = {
|
|
"editor": editor_name,
|
|
"time": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"changes": changes,
|
|
}
|
|
if reason:
|
|
entry["reason"] = reason
|
|
log.append(entry)
|
|
record.edit_log = log
|
|
|
|
|
|
def init_entry(record, creator_name: str):
|
|
"""Initialize edit_log with a creation entry."""
|
|
record.edit_log = [{
|
|
"editor": creator_name,
|
|
"time": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"changes": {},
|
|
}]
|