Move Django apps out of apps/ and mount them under auth/, common/, content/, and cms/ so endpoint paths map directly to the owning app. Co-authored-by: Cursor <cursoragent@cursor.com>
97 lines
2.8 KiB
Python
97 lines
2.8 KiB
Python
"""将前台默认导航结构同步到 Column 表(可重复执行)。"""
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from content.models import Column, NavPosition
|
|
|
|
|
|
# 与 ui/src/config/nav.js 对齐
|
|
TOP_TREE = [
|
|
("首页", "/index", []),
|
|
(
|
|
"排名",
|
|
"/guideRanking",
|
|
[
|
|
("中国指南排名", "/guideRanking?type=1"),
|
|
("中国共识排名", "/guideRanking?type=2"),
|
|
("中国传统医学指南排名", "/guideRanking?type=1&scope=tcm"),
|
|
("中国传统医学共识排名", "/guideRanking?type=2&scope=tcm"),
|
|
("制订机构排名", "/organizationRanking"),
|
|
("发布杂志排名", "/magazineRanking"),
|
|
],
|
|
),
|
|
("数据库", "/guidelineAndConsensus", []),
|
|
("制订机构", "/organization", []),
|
|
("评级工作组", "/specialist", []),
|
|
(
|
|
"关于我们",
|
|
"/about",
|
|
[
|
|
("关于我们", "/about"),
|
|
("版权声明", "/statement"),
|
|
("联系我们", "/relation"),
|
|
],
|
|
),
|
|
]
|
|
|
|
FOOTER_TREE = [
|
|
(
|
|
"关于我们",
|
|
"/about",
|
|
[
|
|
("关于我们", "/about"),
|
|
("版权声明", "/statement"),
|
|
("联系我们", "/relation"),
|
|
],
|
|
),
|
|
(
|
|
"排名",
|
|
"/guideRanking",
|
|
[
|
|
("中国指南排名", "/guideRanking?type=1"),
|
|
("制订机构排名", "/organizationRanking"),
|
|
("发布杂志排名", "/magazineRanking"),
|
|
],
|
|
),
|
|
(
|
|
"数据库",
|
|
"/guidelineAndConsensus",
|
|
[
|
|
("指南/共识", "/guidelineAndConsensus"),
|
|
("制订机构", "/organization"),
|
|
("评级工作组", "/specialist"),
|
|
("新闻通知", "/newsList"),
|
|
],
|
|
),
|
|
]
|
|
|
|
|
|
def _create_tree(tree, position):
|
|
for sort, (name, path, children) in enumerate(tree, start=1):
|
|
parent = Column.objects.create(
|
|
name=name,
|
|
path=path,
|
|
position=position,
|
|
sort=sort,
|
|
)
|
|
for csort, (cname, cpath) in enumerate(children, start=1):
|
|
Column.objects.create(
|
|
name=cname,
|
|
path=cpath,
|
|
position=position,
|
|
parent=parent,
|
|
sort=csort,
|
|
)
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "清空并重建顶部/底部栏目,使其与前台默认导航一致"
|
|
|
|
def handle(self, *args, **options):
|
|
deleted, _ = Column.all_objects.all().delete()
|
|
self.stdout.write(f"已清除栏目 {deleted} 条")
|
|
_create_tree(TOP_TREE, NavPosition.TOP)
|
|
_create_tree(FOOTER_TREE, NavPosition.BOTTOM)
|
|
total = Column.objects.count()
|
|
self.stdout.write(self.style.SUCCESS(f"已写入栏目 {total} 条(顶部+底部)"))
|