加入「拾脉」:XMind 学习目录与在线预览

- mindmaps 增加目录模型,脑图归属目录,支持子目录
- 前端上传 .xmind,后台解析 Zen / 旧版并入库
- simple-mind-map 只读预览:缩放、适应、全屏、文字大纲
- 目录与脑图增删改查,复用拾匣密码
- 首页页脚新增拾脉入口,保留旧脑图数据
This commit is contained in:
2026-11-21 13:31:26 +08:00
parent 128dc20cd5
commit 7c6e5d45d1
14 changed files with 2008 additions and 58 deletions
+33 -14
View File
@@ -1,29 +1,48 @@
from django.contrib import admin
from django import forms
from .models import MindMap
from .models import MindFolder, MindMap
@admin.register(MindFolder)
class MindFolderAdmin(admin.ModelAdmin):
list_display = ("id", "name", "parent", "map_count", "created_at")
search_fields = ("name", "description")
prepopulated_fields = {"slug": ("name",)}
readonly_fields = ("created_at", "updated_at")
@admin.display(description="脑图数")
def map_count(self, obj):
return obj.maps.count()
@admin.register(MindMap)
class MindMapAdmin(admin.ModelAdmin):
list_display = ("title", "created_at", "has_mindmap")
search_fields = ("title",)
list_display = (
"id", "title", "folder", "sheet_count", "node_count", "has_mindmap", "updated_at",
)
list_filter = ("folder", "created_at")
search_fields = ("title", "description", "original_name")
prepopulated_fields = {"slug": ("title",)}
readonly_fields = ("updated_at",)
readonly_fields = ("created_at", "updated_at", "original_name", "sheet_count")
list_select_related = ("folder",)
@admin.display(description="节点")
def node_count(self, obj):
return obj.node_total
@admin.display(boolean=True, description="已解析")
def has_mindmap(self, obj):
return bool(obj.mindmap_data and obj.mindmap_data.get("data"))
has_mindmap.boolean = True
has_mindmap.short_description = "已解析"
def save_model(self, request, obj, form, change):
is_new = not obj.pk
super().save_model(request, obj, form, change)
if "xmind_file" in form.changed_data and obj.xmind_file:
if obj.xmind_file and ("xmind_file" in form.changed_data or not obj.mindmap_data):
try:
obj.parse_and_store(obj.xmind_file.path)
self.message_user(request, f"脑图「{obj.title}」解析成功")
except Exception as e:
self.message_user(request, "脑图「{}」解析成功".format(obj.title))
except Exception as exc:
self.message_user(
request, f"解析失败: {e}", level="error"
)
request,
"解析失败:{}".format(exc),
level="error",
)