Commit 474b9f8e authored by James Valleroy's avatar James Valleroy

backups: Add apps selection to restore form

Signed-off-by: James Valleroy's avatarJames Valleroy <>
parent 6c89cc31
......@@ -57,3 +57,19 @@ class ExportArchiveForm(forms.Form):
"""Initialize the form with disk choices."""
super().__init__(*args, **kwargs)
self.fields['disk'].choices = get_export_locations()
class RestoreForm(forms.Form):
selected_apps = forms.MultipleChoiceField(
label=_('Restore apps'),
help_text=_('Apps data to restore from the backup'),
def __init__(self, *args, **kwargs):
"""Initialize the form with selectable apps."""
super().__init__(*args, **kwargs)
apps = _list_of_all_apps_for_backup()
# TODO: Only list apps included in the backup file.
self.fields['selected_apps'].choices = [
(app[0], app[1].name) for app in apps]
self.fields['selected_apps'].initial = [app[0] for app in apps]
......@@ -47,6 +47,8 @@
<form class="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-danger"
value="{% blocktrans trimmed %}
Restore data from {{ name }}
......@@ -31,7 +31,7 @@ from urllib.parse import unquote
from plinth.modules import backups
from .backups import _list_of_all_apps_for_backup
from .forms import CreateArchiveForm, ExportArchiveForm
from .forms import CreateArchiveForm, ExportArchiveForm, RestoreForm
class IndexView(TemplateView):
......@@ -125,9 +125,13 @@ class ExportArchiveView(SuccessMessageMixin, FormView):
return super().form_valid(form)
class RestoreView(SuccessMessageMixin, TemplateView):
class RestoreView(SuccessMessageMixin, FormView):
"""View to restore files from an exported archive."""
form_class = RestoreForm
prefix = 'backups'
template_name = 'backups_restore.html'
success_url = reverse_lazy('backups:index')
success_message = _('Restored files from backup.')
def get_context_data(self, **kwargs):
"""Return additional context for rendering the template."""
......@@ -137,8 +141,9 @@ class RestoreView(SuccessMessageMixin, TemplateView):
context['name'] = self.kwargs['name']
return context
def post(self, request, label, name):
def form_valid(self, form):
"""Restore files from the archive on valid form submission."""
backups.restore_exported(label, name)
messages.success(request, _('Restored data from backup.'))
return redirect(reverse_lazy('backups:index'))
return super().form_valid(form)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment