From e2843990a76861de9220c37de854b40efe6b458c Mon Sep 17 00:00:00 2001 From: Kyle Gabriel Date: Mon, 30 Sep 2024 20:29:41 -0400 Subject: [PATCH] Allow deletion of the last remaining Dashboard --- CHANGELOG.md | 4 ++++ mycodo/mycodo_flask/utils/utils_dashboard.py | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cf6a2cb8..d50ee64a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ - Fix restoring mycodo/user_scripts during upgrade - Fix documentation generation +### Miscellaneous + + - Allow deletion of the last remaining Dashboard + ## 8.16.0 (2024.09.29) diff --git a/mycodo/mycodo_flask/utils/utils_dashboard.py b/mycodo/mycodo_flask/utils/utils_dashboard.py index e91d686f8..d80b704ce 100644 --- a/mycodo/mycodo_flask/utils/utils_dashboard.py +++ b/mycodo/mycodo_flask/utils/utils_dashboard.py @@ -129,11 +129,11 @@ def dashboard_del(form): action=TRANSLATIONS['delete']['title'], controller=TRANSLATIONS['dashboard']['title']) error = [] + create_new_dash = False dashboards = Dashboard.query.all() if len(dashboards) == 1: - flash('Cannot delete the only remaining dashboard.', 'error') - return + create_new_dash = True widgets = Widget.query.filter( Widget.dashboard_id == form.dashboard_id.data).all() @@ -142,6 +142,11 @@ def dashboard_del(form): delete_entry_with_id(Dashboard, form.dashboard_id.data) + if create_new_dash: + new_dash = Dashboard() + new_dash.name = 'New Dashboard' + new_dash.save() + flash_success_errors( error, action, url_for('routes_dashboard.page_dashboard_default'))