feat: Allow tribe renaming
All checks were successful
Build Docker / Build Main Image (push) Successful in 17s
Build Docker / Build SLDs Image (push) Successful in 19s

This commit is contained in:
Nathan Woodburn 2023-11-22 13:16:36 +11:00
parent bd149f012e
commit 8ecc960c58
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 24 additions and 0 deletions

10
db.py
View File

@ -361,3 +361,13 @@ def delete_tribe(tribe):
connection.commit()
cursor.close()
connection.close()
def rename_tribe(old,new):
connection = mysql.connector.connect(**dbargs)
cursor = connection.cursor()
cursor.execute("""
UPDATE tribes SET tribe = %s WHERE tribe = %s
""", (new,old))
connection.commit()
cursor.close()
connection.close()

14
main.py
View File

@ -523,6 +523,20 @@ def edit_tribe():
# Convert to json
data = json.dumps(data)
db.update_tribe_data_raw(tribe,data)
# Check if tribe name changed
if tribe != request.form['tribe']:
# Verify new tribe name
new_tribe = request.form['tribe'].strip().lower()
if not re.match("^[a-z0-9_]*$", new_tribe):
return error('Sorry tribe can only contain lowercase letters, numbers and underscores')
if new_tribe.startswith("_") or new_tribe.endswith("_"):
return error('Sorry tribe can\'t start or end with an underscore')
# Delete old tribe
db.rename_tribe(tribe,new_tribe)
return redirect('/edit_tribe')
@app.route('/remove_member')