diff --git a/db.py b/db.py index f06ca21..1a21ead 100644 --- a/db.py +++ b/db.py @@ -360,4 +360,14 @@ def delete_tribe(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() \ No newline at end of file diff --git a/main.py b/main.py index 6fb0657..874e0ee 100644 --- a/main.py +++ b/main.py @@ -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')