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()
|
db = get_db()
|
||||||
try:
|
try:
|
||||||
if request.method == "POST":
|
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 = []
|
values = []
|
||||||
set_clauses = []
|
set_clauses = []
|
||||||
for field in CHAR_STAT_FIELDS:
|
for field in CHAR_STAT_FIELDS:
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
<div class="card" style="max-width:600px;">
|
<div class="card" style="max-width:600px;">
|
||||||
<h2 style="margin-top:0;">Charakter: {{ char.char_name }} <span class="badge ok">Account: {{ char.account_name }}</span></h2>
|
<h2 style="margin-top:0;">Charakter: {{ char.char_name }} <span class="badge ok">Account: {{ char.account_name }}</span></h2>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
|
<label>Charaktername</label>
|
||||||
|
<input type="text" name="char_name" value="{{ char.char_name }}" required>
|
||||||
|
|
||||||
<label>Standort (wirkt beim nächsten Login)</label>
|
<label>Standort (wirkt beim nächsten Login)</label>
|
||||||
<select name="respawnid">
|
<select name="respawnid">
|
||||||
<option value="{{ char.respawnid }}">-- aktuell: Zone #{{ char.respawnid }} --</option>
|
<option value="{{ char.respawnid }}">-- aktuell: Zone #{{ char.respawnid }} --</option>
|
||||||
|
|||||||
Reference in new issue
Block a user