Add character rename to admin panel
Renaming checks for a name collision first (characters.char_name has no unique constraint in the schema, so this has to be enforced at the application level to avoid two characters silently sharing a name), and also updates list_friend.namefriend for any rows referencing this character's id -- that column is a denormalized display-name cache in other players' friend lists and would otherwise go stale on rename. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
315f64cf95
commit
a07c2e0a3f
2 files changed
+34
No files matched your search
@@ -258,6 +258,37 @@ def edit_character(char_id):
|
||||
db = get_db()
|
||||
try:
|
||||
if request.method == "POST":
|
||||
with db.cursor() as cur:
|
||||
cur.execute("SELECT char_name FROM characters WHERE id=%s", (char_id,))
|
||||
old = cur.fetchone()
|
||||
if not old:
|
||||
flash("Charakter nicht gefunden.")
|
||||
return redirect(url_for("characters"))
|
||||
|
||||
new_name = request.form.get("char_name", "").strip()
|
||||
if new_name and new_name != old["char_name"]:
|
||||
with db.cursor() as cur:
|
||||
cur.execute(
|
||||
"SELECT id FROM characters WHERE char_name=%s AND id<>%s",
|
||||
(new_name, char_id),
|
||||
)
|
||||
if cur.fetchone():
|
||||
flash(f"Name '{new_name}' ist bereits vergeben.")
|
||||
return redirect(url_for("edit_character", char_id=char_id))
|
||||
cur.execute(
|
||||
"UPDATE characters SET char_name=%s WHERE id=%s",
|
||||
(new_name, char_id),
|
||||
)
|
||||
# namefriend is a denormalized display-name cache in other
|
||||
# players' friend lists (list_friend.idfriend references
|
||||
# this character's id) -- keep it in sync so renames
|
||||
# don't leave stale names in friend lists.
|
||||
cur.execute(
|
||||
"UPDATE list_friend SET namefriend=%s WHERE idfriend=%s",
|
||||
(new_name, char_id),
|
||||
)
|
||||
flash(f"Charakter '{old['char_name']}' umbenannt in '{new_name}'.")
|
||||
|
||||
values = []
|
||||
set_clauses = []
|
||||
for field in CHAR_STAT_FIELDS:
|
||||
|
||||
Reference in new issue
Block a user