fixed deletion

This commit is contained in:
pika 2025-04-03 12:51:31 +02:00
parent e9d1f985ae
commit 78ce15e82d
2 changed files with 94 additions and 58 deletions

View file

@ -409,15 +409,27 @@ def app_edit(app_id):
@bp.route("/app/<int:app_id>/delete", methods=["POST"])
@login_required
def app_delete(app_id):
"""Delete an application"""
"""Delete an application and all its ports"""
app = App.query.get_or_404(app_id)
app_name = app.name
server_id = app.server_id
db.session.delete(app)
db.session.commit()
flash("Application deleted successfully", "success")
return redirect(url_for("dashboard.server_view", server_id=server_id))
try:
# First explicitly delete all associated ports
Port.query.filter_by(app_id=app_id).delete()
# Then delete the application
db.session.delete(app)
db.session.commit()
flash(f"Application '{app_name}' has been deleted", "success")
# Redirect back to server view
return redirect(url_for("dashboard.server_view", server_id=server_id))
except Exception as e:
db.session.rollback()
flash(f"Error deleting application: {str(e)}", "danger")
return redirect(url_for("dashboard.app_view", app_id=app_id))
@bp.route("/settings", methods=["GET", "POST"])