From 5ec14f7c97a890c0c802ec9561453bbb2f6dc1ad Mon Sep 17 00:00:00 2001
From: Prachi Srivastava
Date: Fri, 23 Nov 2018 14:52:09 +0530
Subject: [PATCH] Changes delete all to delete selected in snapshot
Reviewed-by: James Valleroy
---
...ete.html => snapshot_delete_selected.html} | 23 +++++++------
.../snapshot/templates/snapshot_manage.html | 29 ++++------------
plinth/modules/snapshot/urls.py | 2 +-
plinth/modules/snapshot/views.py | 34 ++++++++++++-------
4 files changed, 41 insertions(+), 47 deletions(-)
rename plinth/modules/snapshot/templates/{snapshot_delete.html => snapshot_delete_selected.html} (71%)
diff --git a/plinth/modules/snapshot/templates/snapshot_delete.html b/plinth/modules/snapshot/templates/snapshot_delete_selected.html
similarity index 71%
rename from plinth/modules/snapshot/templates/snapshot_delete.html
rename to plinth/modules/snapshot/templates/snapshot_delete_selected.html
index 58d2880dd..dd95e05ef 100644
--- a/plinth/modules/snapshot/templates/snapshot_delete.html
+++ b/plinth/modules/snapshot/templates/snapshot_delete_selected.html
@@ -24,7 +24,7 @@
{% block content %}
{{ title }}
- {% trans "Delete this snapshot permanently?" %}
+ {% trans "Delete the following snapshots permanently?" %}
@@ -33,22 +33,23 @@
| {% trans "Description" %} |
-
- | {{ snapshot.number }} |
- {{ snapshot.date }} |
- {{ snapshot.description }} |
-
+ {% for snapshot in snapshot_list %}
+ {% if not snapshot.is_default %}
+
+ | {{ snapshot.number }} |
+ {{ snapshot.date }} |
+ {{ snapshot.description }} |
+
+ {% endif %}
+ {% endfor %}
diff --git a/plinth/modules/snapshot/templates/snapshot_manage.html b/plinth/modules/snapshot/templates/snapshot_manage.html
index 3c0ef1741..c1272c82a 100644
--- a/plinth/modules/snapshot/templates/snapshot_manage.html
+++ b/plinth/modules/snapshot/templates/snapshot_manage.html
@@ -23,27 +23,19 @@
{% block content %}
{% block configuration %}
+
{% endblock %}
{% endblock %}
diff --git a/plinth/modules/snapshot/urls.py b/plinth/modules/snapshot/urls.py
index 5ac318b16..66f49c95e 100644
--- a/plinth/modules/snapshot/urls.py
+++ b/plinth/modules/snapshot/urls.py
@@ -25,8 +25,8 @@ from . import views
urlpatterns = [
url(r'^sys/snapshot/$', views.index, name='index'),
url(r'^sys/snapshot/manage/$', views.manage, name='manage'),
- url(r'^sys/snapshot/(?P\d+)/delete$', views.delete, name='delete'),
url(r'^sys/snapshot/all/delete$', views.delete_all, name='delete-all'),
+ url(r'^sys/snapshot/selected/delete$', views.delete_selected, name='delete-selected'),
url(r'^sys/snapshot/(?P\d+)/rollback$', views.rollback,
name='rollback'),
]
diff --git a/plinth/modules/snapshot/views.py b/plinth/modules/snapshot/views.py
index 7f3df7da8..7393efaa6 100644
--- a/plinth/modules/snapshot/views.py
+++ b/plinth/modules/snapshot/views.py
@@ -70,6 +70,10 @@ def manage(request):
if 'create' in request.POST:
actions.superuser_run('snapshot', ['create'])
messages.success(request, _('Created snapshot.'))
+ if 'delete_selected' in request.POST:
+ snapshot_to_delete = request.POST.getlist('snapshot_list')
+ request.session['snapshots'] = snapshot_to_delete
+ return redirect(reverse('snapshot:delete-selected'))
output = actions.superuser_run('snapshot', ['list'])
snapshots = json.loads(output)
@@ -124,22 +128,26 @@ def update_configuration(request, old_status, new_status):
exception.args[2]))
-def delete(request, number):
- """Show confirmation to delete a snapshot."""
- if request.method == 'POST':
- actions.superuser_run('snapshot', ['delete', number])
- messages.success(
- request, _('Deleted snapshot #{number}.').format(number=number))
- return redirect(reverse('snapshot:manage'))
-
+def delete_selected(request):
output = actions.superuser_run('snapshot', ['list'])
snapshots = json.loads(output)
- snapshot = next(s for s in snapshots if s['number'] == number)
- return TemplateResponse(request, 'snapshot_delete.html', {
- 'title': _('Delete Snapshot'),
- 'snapshot': snapshot
- })
+ if request.method == 'POST':
+ if 'snapshots' in request.session:
+ to_delete = request.session['snapshots']
+ for snapshot in to_delete:
+ actions.superuser_run('snapshot', ['delete', snapshot])
+ messages.success(request, _('Deleted the selected snapshots'))
+ return redirect(reverse('snapshot:manage'))
+
+ if 'snapshots' in request.session:
+ data = request.session['snapshots']
+ to_delete = list(filter(lambda x: x['number'] in data, snapshots))
+
+ return TemplateResponse(request, 'snapshot_delete_all.html', {
+ 'title': _('Delete Snapshots'),
+ 'snapshots': to_delete
+ })
def delete_all(request):