From fde580807b34439b185f32edbef7e5fca60830b1 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 24 Apr 2024 13:40:17 -0700 Subject: [PATCH] 15815 convert dashboard widgets for users/groups --- .../0115_convert_dashboard_widgets.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 netbox/extras/migrations/0115_convert_dashboard_widgets.py diff --git a/netbox/extras/migrations/0115_convert_dashboard_widgets.py b/netbox/extras/migrations/0115_convert_dashboard_widgets.py new file mode 100644 index 000000000..78863e3c4 --- /dev/null +++ b/netbox/extras/migrations/0115_convert_dashboard_widgets.py @@ -0,0 +1,31 @@ +# Generated by Django 5.0.4 on 2024-04-24 20:09 + +from django.db import migrations + + +def update_dashboard_widgets(apps, schema_editor): + Dashboard = apps.get_model('extras', 'Dashboard') + + for dashboard in Dashboard.objects.all(): + for key, widget in dashboard.config.items(): + breakpoint() + if 'models' in widget['config']: + models = widget['config']['models'] + models = list(map(lambda x: x.replace('users.netboxgroup', 'users.group'), models)) + models = list(map(lambda x: x.replace('users.netboxuser', 'users.user'), models)) + dashboard.config[key]['config']['models'] = models + dashboard.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('extras', '0114_customfield_add_comments'), + ] + + operations = [ + migrations.RunPython( + code=update_dashboard_widgets, + reverse_code=migrations.RunPython.noop + ), + ]