From 90527b799d7238012175640035f25fbb0702ec5a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 30 Mar 2023 12:46:06 -0400 Subject: [PATCH] #9416: Add view to reset user's dashboard --- netbox/extras/urls.py | 1 + netbox/extras/views.py | 30 +++++++++++++++++- netbox/templates/extras/dashboard/reset.html | 8 +++++ netbox/templates/home.html | 33 ++++++++++++-------- 4 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 netbox/templates/extras/dashboard/reset.html diff --git a/netbox/extras/urls.py b/netbox/extras/urls.py index 482e0a554..f04c53add 100644 --- a/netbox/extras/urls.py +++ b/netbox/extras/urls.py @@ -88,6 +88,7 @@ urlpatterns = [ path('changelog//', include(get_model_urls('extras', 'objectchange'))), # User dashboard + path('dashboard/reset/', views.DashboardResetView.as_view(), name='dashboard_reset'), path('dashboard/widgets/add/', views.DashboardWidgetAddView.as_view(), name='dashboardwidget_add'), path('dashboard/widgets//configure/', views.DashboardWidgetConfigView.as_view(), name='dashboardwidget_config'), path('dashboard/widgets//delete/', views.DashboardWidgetDeleteView.as_view(), name='dashboardwidget_delete'), diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 335d98db0..4e25539ce 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -5,6 +5,7 @@ from django.db.models import Count, Q from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponse from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse +from django.utils.translation import gettext as _ from django.views.generic import View from core.choices import JobStatusChoices, ManagedFileRootPathChoices @@ -665,9 +666,36 @@ class JournalEntryBulkDeleteView(generic.BulkDeleteView): # -# Dashboard widgets +# Dashboard & widgets # +class DashboardResetView(LoginRequiredMixin, View): + template_name = 'extras/dashboard/reset.html' + + def get(self, request): + get_object_or_404(Dashboard.objects.all(), user=request.user) + form = ConfirmationForm() + + return render(request, self.template_name, { + 'form': form, + 'return_url': reverse('home'), + }) + + def post(self, request): + dashboard = get_object_or_404(Dashboard.objects.all(), user=request.user) + form = ConfirmationForm(request.POST) + + if form.is_valid(): + dashboard.delete() + messages.success(request, _("Your dashboard has been reset.")) + return redirect(reverse('home')) + + return render(request, self.template_name, { + 'form': form, + 'return_url': reverse('home'), + }) + + class DashboardWidgetAddView(LoginRequiredMixin, View): template_name = 'extras/dashboard/widget_add.html' diff --git a/netbox/templates/extras/dashboard/reset.html b/netbox/templates/extras/dashboard/reset.html new file mode 100644 index 000000000..8acbd3f98 --- /dev/null +++ b/netbox/templates/extras/dashboard/reset.html @@ -0,0 +1,8 @@ +{% extends 'generic/confirmation_form.html' %} + +{% block title %}Reset Dashboard?{% endblock %} + +{% block message %} +

This will remove all configured widgets and restore the default dashboard configuration.

+

This change affects on your dashboard, and will not impact other users.

+{% endblock %} diff --git a/netbox/templates/home.html b/netbox/templates/home.html index a21509994..846ef9758 100644 --- a/netbox/templates/home.html +++ b/netbox/templates/home.html @@ -29,19 +29,26 @@ {% include 'extras/dashboard/widget.html' %} {% endfor %} -
- - Add Widget - - +
+ +
+ + + Reset Dashboard + +
{% endblock content-wrapper %}