dashboard: don't remove cell associated to tile (#18929)

This commit is contained in:
Frédéric Péters 2017-09-25 12:22:29 +02:00
parent 9ae909000e
commit 2d97d98a8c
2 changed files with 13 additions and 3 deletions

View File

@ -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)

View File

@ -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)