From a07c2e0a3f4081075c7cb474fff5284ee25d179b Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 9 Jul 2026 07:59:49 +0200 Subject: [PATCH] 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 --- webadmin/app.py | 31 ++++++++++++++++++++++++++ webadmin/templates/edit_character.html | 3 +++ 2 files changed, 34 insertions(+) diff --git a/webadmin/app.py b/webadmin/app.py index f382694..81866ed 100644 --- a/webadmin/app.py +++ b/webadmin/app.py @@ -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: diff --git a/webadmin/templates/edit_character.html b/webadmin/templates/edit_character.html index 0e6f759..8f108b5 100644 --- a/webadmin/templates/edit_character.html +++ b/webadmin/templates/edit_character.html @@ -4,6 +4,9 @@

Charakter: {{ char.char_name }} Account: {{ char.account_name }}

+ + +