From 4f82be1346aa344da9f144a46726fcf1fd7526aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 25 Sep 2017 12:22:29 +0200 Subject: [PATCH] dashboard: don't remove cell associated to tile (#18929) --- combo/apps/dashboard/views.py | 14 ++++++++++++-- tests/test_dashboard.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/combo/apps/dashboard/views.py b/combo/apps/dashboard/views.py index bbe7774..5805162 100644 --- a/combo/apps/dashboard/views.py +++ b/combo/apps/dashboard/views.py @@ -19,6 +19,7 @@ import json from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied +from django.core.urlresolvers import reverse from django.http import Http404, HttpResponse, HttpResponseRedirect from django.views.decorators.csrf import csrf_exempt from django.views.generic import View @@ -67,7 +68,12 @@ class DashboardAddTileView(View): tile.order = 0 tile.save() - return dashboard_success(request, dashboard, get_cell_data(cell)) + cell_data = get_cell_data(cell) + cell_data['remove_url'] = reverse( + 'combo-dashboard-remove-tile', + kwargs={'cell_reference': cell.get_reference()}) + + return dashboard_success(request, dashboard, cell_data) dashboard_add_tile = DashboardAddTileView.as_view() @@ -84,7 +90,11 @@ class DashboardRemoveTileView(View): dashboard = tile.dashboard cell_data = get_cell_data(cell) tile.delete() - cell.delete() + + # do not remove cell so it can directly be added back + cell_data['add_url'] = reverse( + 'combo-dashboard-add-tile', + kwargs={'cell_reference': cell.get_reference()}) return dashboard_success(request, dashboard, cell_data) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 8e5cb92..1e1539e 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -107,7 +107,7 @@ def test_remove_from_dashboard(app, site): resp = app.get(reverse('combo-dashboard-remove-tile', kwargs={'cell_reference': tile.cell.get_reference()}), status=302) assert Tile.objects.count() == 0 - assert TextCell.objects.count() == 10 + assert TextCell.objects.count() == 11 # the cell itself is kept def test_ajax_remove_from_dashboard(app, site): test_add_to_dashboard(app, site) -- 2.14.1