mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
snapshots: Button to delete all snapshots
- closes #1144 Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
81f4d7ec42
commit
3e5dcfcbf5
6 files changed
+160
-49
No files matched your search
@@ -22,6 +22,29 @@
|
||||
{% load i18n %}
|
||||
|
||||
{% block configuration %}
|
||||
<p>
|
||||
<div class="row">
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="col-xs-6 text-left">
|
||||
<input type="submit" class="btn btn-primary"
|
||||
value="{% trans 'Create Snapshot' %}"/>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="col-xs-6 text-right">
|
||||
<a title="{% trans 'Delete all the snapshots' %}"
|
||||
role="button" class="btn btn-danger"
|
||||
{% if snapshots|length == 1 %}
|
||||
disabled="disabled"
|
||||
{% else %}
|
||||
href="{% url 'snapshot:delete-all' %}"
|
||||
{% endif %}>
|
||||
{% trans 'Delete All' %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
@@ -51,8 +74,8 @@
|
||||
<a href="{% url 'snapshot:rollback' snapshot.number %}"
|
||||
class="btn btn-default btn-sm" role="button"
|
||||
title="{% blocktrans trimmed with number=snapshot.number %}
|
||||
Rollback to snapshot #{{ number }}
|
||||
{% endblocktrans %}">
|
||||
Rollback to snapshot #{{ number }}
|
||||
{% endblocktrans %}">
|
||||
<span class="glyphicon glyphicon-repeat"
|
||||
aria-hidden="true"></span>
|
||||
</a>
|
||||
@@ -62,8 +85,8 @@
|
||||
<a href="{% url 'snapshot:delete' snapshot.number %}"
|
||||
class="btn btn-default btn-sm" role="button"
|
||||
title="{% blocktrans trimmed with number=snapshot.number %}
|
||||
Delete snapshot #{{ number }}
|
||||
{% endblocktrans %}">
|
||||
Delete snapshot #{{ number }}
|
||||
{% endblocktrans %}">
|
||||
<span class="glyphicon glyphicon-trash"
|
||||
aria-hidden="true"></span>
|
||||
</a>
|
||||
@@ -77,13 +100,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="submit" class="btn btn-primary"
|
||||
value="{% trans "Create Snapshot" %}"/>
|
||||
</form>
|
||||
</p>
|
||||
|
||||
{% endblock %}
|
||||
@@ -49,7 +49,7 @@
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="submit" class="btn btn-primary"
|
||||
<input type="submit" class="btn btn-danger"
|
||||
value="{% blocktrans trimmed with number=snapshot.number %}
|
||||
Delete Snapshot #{{ number }}
|
||||
{% endblocktrans %}"/>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{{ title }}</h2>
|
||||
|
||||
<p>{% trans "Delete the following snapshots permanently?" %}</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<table class="table table-bordered table-condensed table-striped">
|
||||
<thead>
|
||||
<th>{% trans "Number" %}</th>
|
||||
<th>{% trans "Date" %}</th>
|
||||
<th>{% trans "Description" %}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for snapshot in snapshots %}
|
||||
<tr>
|
||||
<td>{{ snapshot.number }}</td>
|
||||
<td>{{ snapshot.date }}</td>
|
||||
<td>{{ snapshot.description }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="submit" class="btn btn-danger"
|
||||
value="{% trans 'Delete Snapshots' %}"/>
|
||||
</form>
|
||||
</p>
|
||||
|
||||
{% endblock %}
|
||||
@@ -14,7 +14,6 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
URLs for the snapshot module.
|
||||
"""
|
||||
@@ -23,10 +22,10 @@ from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^sys/snapshot/$', views.index, name='index'),
|
||||
url(r'^sys/snapshot/(?P<number>\d+)/delete$', views.delete, name='delete'),
|
||||
url(r'^sys/snapshot/all/delete$', views.delete_all, name='delete-all'),
|
||||
url(r'^sys/snapshot/(?P<number>\d+)/rollback$', views.rollback,
|
||||
name='rollback'),
|
||||
]
|
||||
@@ -14,17 +14,17 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Views for snapshot module.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
import json
|
||||
|
||||
from plinth import actions
|
||||
from plinth.modules import snapshot as snapshot_module
|
||||
@@ -39,40 +39,55 @@ def index(request):
|
||||
output = actions.superuser_run('snapshot', ['list'])
|
||||
snapshots = json.loads(output)
|
||||
|
||||
return TemplateResponse(request, 'snapshot.html',
|
||||
{'title': snapshot_module.name,
|
||||
'description': snapshot_module.description,
|
||||
'snapshots': snapshots})
|
||||
return TemplateResponse(request, 'snapshot.html', {
|
||||
'title': snapshot_module.name,
|
||||
'description': snapshot_module.description,
|
||||
'snapshots': snapshots
|
||||
})
|
||||
|
||||
|
||||
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))
|
||||
messages.success(request,
|
||||
_('Deleted snapshot #{number}.').format(
|
||||
number=number))
|
||||
return redirect(reverse('snapshot:index'))
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
|
||||
def delete_all(request):
|
||||
"""Show confirmation to delete all snapshots."""
|
||||
if request.method == 'POST':
|
||||
actions.superuser_run('snapshot', ['delete-all'])
|
||||
messages.success(request, _('Deleted all snapshots.'))
|
||||
return redirect(reverse('snapshot:index'))
|
||||
|
||||
output = actions.superuser_run('snapshot', ['list'])
|
||||
snapshots = json.loads(output)
|
||||
|
||||
snapshot = None
|
||||
for current_snapshot in snapshots:
|
||||
if current_snapshot['number'] == number:
|
||||
snapshot = current_snapshot
|
||||
|
||||
return TemplateResponse(request, 'snapshot_delete.html',
|
||||
{'title': _('Delete Snapshot'),
|
||||
'snapshot': snapshot})
|
||||
return TemplateResponse(request, 'snapshot_delete_all.html', {
|
||||
'title': _('Delete Snapshots'),
|
||||
'snapshots': snapshots[1:]
|
||||
})
|
||||
|
||||
|
||||
def rollback(request, number):
|
||||
"""Show confirmation to rollback to a snapshot."""
|
||||
if request.method == 'POST':
|
||||
actions.superuser_run('snapshot', ['rollback', number])
|
||||
messages.success(
|
||||
request,
|
||||
_('Rolled back to snapshot #{number}.').format(number=number))
|
||||
messages.success(request,
|
||||
_('Rolled back to snapshot #{number}.').format(
|
||||
number=number))
|
||||
messages.warning(
|
||||
request,
|
||||
_('The system must be restarted to complete the rollback.'))
|
||||
@@ -86,6 +101,7 @@ def rollback(request, number):
|
||||
if current_snapshot['number'] == number:
|
||||
snapshot = current_snapshot
|
||||
|
||||
return TemplateResponse(request, 'snapshot_rollback.html',
|
||||
{'title': _('Rollback to Snapshot'),
|
||||
'snapshot': snapshot})
|
||||
return TemplateResponse(request, 'snapshot_rollback.html', {
|
||||
'title': _('Rollback to Snapshot'),
|
||||
'snapshot': snapshot
|
||||
})
|
||||
Reference in new issue
Block a user