feat(admin): 管理员可修改队员昵称与球衣号(仅 admin 可操作)
Browse files- app.py +14 -2
- src/repo.py +17 -0
- src/view_admin.py +21 -7
app.py
CHANGED
|
@@ -245,7 +245,13 @@ def server(input: Inputs, output: Outputs, session: Session) -> None:
|
|
| 245 |
if not uid_raw:
|
| 246 |
return ui.div("请选择要编辑的队员。", class_="sde-empty")
|
| 247 |
uid = int(uid_raw)
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
@reactive.effect
|
| 251 |
@reactive.event(input.btn_ae_save, ignore_init=True)
|
|
@@ -257,6 +263,10 @@ def server(input: Inputs, output: Outputs, session: Session) -> None:
|
|
| 257 |
ui.notification_show("请先选择队员", type="warning")
|
| 258 |
return
|
| 259 |
uid = int(uid_raw)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
repo.set_goalkeeper(uid, bool(input.ae_gk()))
|
| 261 |
for m in repo.player_matchlog(uid):
|
| 262 |
mid = m["id"]
|
|
@@ -266,7 +276,7 @@ def server(input: Inputs, output: Outputs, session: Session) -> None:
|
|
| 266 |
input[f"aatt_{mid}"](), input[f"asv_{mid}"](),
|
| 267 |
)
|
| 268 |
bump()
|
| 269 |
-
ui.notification_show("已保存该队员数据 ✅", type="message")
|
| 270 |
|
| 271 |
# ------------------------------------------------------------------ 管理:结算本场 MVP
|
| 272 |
@render.ui
|
|
@@ -400,7 +410,9 @@ def server(input: Inputs, output: Outputs, session: Session) -> None:
|
|
| 400 |
str(x["id"]): f'{x["display_name"]} ({x["username"]})'
|
| 401 |
for x in repo.list_users()
|
| 402 |
}
|
|
|
|
| 403 |
ui.update_select("rp_user", choices=choices)
|
|
|
|
| 404 |
|
| 405 |
|
| 406 |
app = App(app_ui, server, static_assets={"/static": str(config.WWW_DIR)})
|
|
|
|
| 245 |
if not uid_raw:
|
| 246 |
return ui.div("请选择要编辑的队员。", class_="sde-empty")
|
| 247 |
uid = int(uid_raw)
|
| 248 |
+
info = next((x for x in repo.list_users() if x["id"] == uid), None)
|
| 249 |
+
return views.admin_edit_player_view(
|
| 250 |
+
repo.player_matchlog(uid),
|
| 251 |
+
user_is_gk(uid),
|
| 252 |
+
info["display_name"] if info else "",
|
| 253 |
+
info["jersey"] if info else None,
|
| 254 |
+
)
|
| 255 |
|
| 256 |
@reactive.effect
|
| 257 |
@reactive.event(input.btn_ae_save, ignore_init=True)
|
|
|
|
| 263 |
ui.notification_show("请先选择队员", type="warning")
|
| 264 |
return
|
| 265 |
uid = int(uid_raw)
|
| 266 |
+
# 改昵称 / 球衣号(仅 admin 可到这里)
|
| 267 |
+
jraw = (input.ae_jersey() or "").strip()
|
| 268 |
+
jersey = int(jraw) if jraw.isdigit() else None
|
| 269 |
+
repo.update_player_profile(uid, input.ae_name() or "", jersey)
|
| 270 |
repo.set_goalkeeper(uid, bool(input.ae_gk()))
|
| 271 |
for m in repo.player_matchlog(uid):
|
| 272 |
mid = m["id"]
|
|
|
|
| 276 |
input[f"aatt_{mid}"](), input[f"asv_{mid}"](),
|
| 277 |
)
|
| 278 |
bump()
|
| 279 |
+
ui.notification_show("已保存该队员资料与数据 ✅", type="message")
|
| 280 |
|
| 281 |
# ------------------------------------------------------------------ 管理:结算本场 MVP
|
| 282 |
@render.ui
|
|
|
|
| 410 |
str(x["id"]): f'{x["display_name"]} ({x["username"]})'
|
| 411 |
for x in repo.list_users()
|
| 412 |
}
|
| 413 |
+
# 重置密码、编辑队员两个下拉共用同一份选项;改名后即时同步显示
|
| 414 |
ui.update_select("rp_user", choices=choices)
|
| 415 |
+
ui.update_select("ae_user", choices=choices)
|
| 416 |
|
| 417 |
|
| 418 |
app = App(app_ui, server, static_assets={"/static": str(config.WWW_DIR)})
|
src/repo.py
CHANGED
|
@@ -91,6 +91,23 @@ def add_user(
|
|
| 91 |
)
|
| 92 |
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
def set_goalkeeper(user_id: int, is_goalkeeper: bool) -> None:
|
| 95 |
"""标记/取消某队员为门将(决定是否显示扑救录入、是否进扑救榜)。"""
|
| 96 |
with get_session() as s:
|
|
|
|
| 91 |
)
|
| 92 |
|
| 93 |
|
| 94 |
+
def update_player_profile(
|
| 95 |
+
user_id: int, display_name: str, jersey: Optional[int]
|
| 96 |
+
) -> None:
|
| 97 |
+
"""管理员修改队员的显示名(昵称)与球衣号;不改登录名与密码。
|
| 98 |
+
|
| 99 |
+
display_name 为空则忽略改名(避免误清空);jersey 为 None 表示无球衣号。
|
| 100 |
+
"""
|
| 101 |
+
with get_session() as s:
|
| 102 |
+
u = s.get(User, user_id)
|
| 103 |
+
if u is None:
|
| 104 |
+
return
|
| 105 |
+
name = (display_name or "").strip()
|
| 106 |
+
if name:
|
| 107 |
+
u.display_name = name
|
| 108 |
+
u.jersey_number = jersey
|
| 109 |
+
|
| 110 |
+
|
| 111 |
def set_goalkeeper(user_id: int, is_goalkeeper: bool) -> None:
|
| 112 |
"""标记/取消某队员为门将(决定是否显示扑救录入、是否进扑救榜)。"""
|
| 113 |
with get_session() as s:
|
src/view_admin.py
CHANGED
|
@@ -68,14 +68,15 @@ def _admin_panel(user_choices: dict[str, str]) -> ui.Tag:
|
|
| 68 |
icon="➕",
|
| 69 |
)
|
| 70 |
edit_player = theme.card(
|
| 71 |
-
"编辑队员数据",
|
| 72 |
ui.div(
|
| 73 |
-
"选择队员后可逐场修改
|
|
|
|
| 74 |
class_="sde-sub",
|
| 75 |
),
|
| 76 |
ui.input_select("ae_user", "选择队员", user_choices),
|
| 77 |
ui.output_ui("admin_edit_player"),
|
| 78 |
-
ui.input_action_button("btn_ae_save", "💾 保存该队员数据", class_="btn-primary"),
|
| 79 |
icon="✏️",
|
| 80 |
)
|
| 81 |
reset_pw = theme.card(
|
|
@@ -187,17 +188,29 @@ def admin_players_view(users: list[dict[str, Any]]) -> ui.Tag:
|
|
| 187 |
)
|
| 188 |
|
| 189 |
|
| 190 |
-
def admin_edit_player_view(
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
输入 id 用 a 前缀(aatt_/ag_/aa_/asv_),与队员本人录入的 id 不冲突。
|
| 194 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
gk_switch = ui.input_switch(
|
| 196 |
"ae_gk", "该队员是门将(计入扑救榜,可录扑救)", value=bool(is_gk)
|
| 197 |
)
|
| 198 |
if not matchlog:
|
| 199 |
return ui.div(
|
| 200 |
-
|
|
|
|
| 201 |
)
|
| 202 |
head = ui.tags.tr(
|
| 203 |
*[ui.tags.th(h) for h in ["日期", "对手", "出勤", "进球", "助攻", "扑救"]]
|
|
@@ -216,6 +229,7 @@ def admin_edit_player_view(matchlog: list[dict[str, Any]], is_gk: bool) -> ui.Ta
|
|
| 216 |
)
|
| 217 |
)
|
| 218 |
return ui.div(
|
|
|
|
| 219 |
gk_switch,
|
| 220 |
ui.div(
|
| 221 |
ui.tags.table(
|
|
|
|
| 68 |
icon="➕",
|
| 69 |
)
|
| 70 |
edit_player = theme.card(
|
| 71 |
+
"编辑队员资料与数据",
|
| 72 |
ui.div(
|
| 73 |
+
"选择队员后可改其 昵称(显示名)/ 球衣号 / 门将标记,并逐场修改 出勤/进球/助攻/扑救。"
|
| 74 |
+
"例如把 Sunny 改成 晴朗。改完点保存。(登录名不变,不影响登录)",
|
| 75 |
class_="sde-sub",
|
| 76 |
),
|
| 77 |
ui.input_select("ae_user", "选择队员", user_choices),
|
| 78 |
ui.output_ui("admin_edit_player"),
|
| 79 |
+
ui.input_action_button("btn_ae_save", "💾 保存该队员资料与数据", class_="btn-primary"),
|
| 80 |
icon="✏️",
|
| 81 |
)
|
| 82 |
reset_pw = theme.card(
|
|
|
|
| 188 |
)
|
| 189 |
|
| 190 |
|
| 191 |
+
def admin_edit_player_view(
|
| 192 |
+
matchlog: list[dict[str, Any]],
|
| 193 |
+
is_gk: bool,
|
| 194 |
+
display_name: str = "",
|
| 195 |
+
jersey: Any = None,
|
| 196 |
+
) -> ui.Tag:
|
| 197 |
+
"""管理员编辑某队员:昵称 / 球衣号 / 门将开关 + 逐场 出勤/进球/助攻/扑救。
|
| 198 |
|
| 199 |
+
输入 id 用 a 前缀(ae_name/ae_jersey/aatt_/ag_/aa_/asv_),与队员本人录入的 id 不冲突。
|
| 200 |
"""
|
| 201 |
+
profile = ui.layout_columns(
|
| 202 |
+
ui.input_text("ae_name", "昵称(显示名)", value=display_name or ""),
|
| 203 |
+
ui.input_text("ae_jersey", "球衣号", value=("" if jersey in (None, "") else str(jersey))),
|
| 204 |
+
col_widths=[6, 6],
|
| 205 |
+
fill=False,
|
| 206 |
+
)
|
| 207 |
gk_switch = ui.input_switch(
|
| 208 |
"ae_gk", "该队员是门将(计入扑救榜,可录扑救)", value=bool(is_gk)
|
| 209 |
)
|
| 210 |
if not matchlog:
|
| 211 |
return ui.div(
|
| 212 |
+
profile, gk_switch,
|
| 213 |
+
ui.div("该队员暂无可编辑比赛,请先录入比赛。", class_="sde-empty"),
|
| 214 |
)
|
| 215 |
head = ui.tags.tr(
|
| 216 |
*[ui.tags.th(h) for h in ["日期", "对手", "出勤", "进球", "助攻", "扑救"]]
|
|
|
|
| 229 |
)
|
| 230 |
)
|
| 231 |
return ui.div(
|
| 232 |
+
profile,
|
| 233 |
gk_switch,
|
| 234 |
ui.div(
|
| 235 |
ui.tags.table(
|