diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index ac70ad2fa..5b0d9c07f 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -110,9 +110,10 @@ class CreateArchiveForm(forms.Form): components = api.get_all_components_for_backup() choices = _get_app_choices(components) self.fields['selected_apps'].choices = choices - self.fields['selected_apps'].initial = [ - choice[0] for choice in choices - ] + if not self.initial or 'selected_apps' not in self.initial: + self.fields['selected_apps'].initial = [ + choice[0] for choice in choices + ] self.fields['repository'].choices = _get_repository_choices() diff --git a/plinth/modules/backups/urls.py b/plinth/modules/backups/urls.py index 4aace50db..d8876b27f 100644 --- a/plinth/modules/backups/urls.py +++ b/plinth/modules/backups/urls.py @@ -15,8 +15,8 @@ urlpatterns = [ re_path(r'^sys/backups/$', BackupsView.as_view(), name='index'), re_path(r'^sys/backups/(?P[^/]+)/schedule/$', ScheduleView.as_view(), name='schedule'), - re_path(r'^sys/backups/create/$', CreateArchiveView.as_view(), - name='create'), + re_path(r'^sys/backups/create/(?:(?P[1-9a-z\-_]+)/)?$', + CreateArchiveView.as_view(), name='create'), re_path(r'^sys/backups/(?P[^/]+)/download/(?P[^/]+)/$', DownloadArchiveView.as_view(), name='download'), re_path(r'^sys/backups/(?P[^/]+)/delete/(?P[^/]+)/$', diff --git a/plinth/modules/backups/views.py b/plinth/modules/backups/views.py index fdadea719..2dc0e7407 100644 --- a/plinth/modules/backups/views.py +++ b/plinth/modules/backups/views.py @@ -116,6 +116,14 @@ class CreateArchiveView(SuccessMessageMixin, FormView): context['title'] = _('Create a new backup') return context + def get_initial(self): + """Return initialization arguments to the form.""" + initial = super().get_initial() + if 'app_id' in self.kwargs: + initial['selected_apps'] = [self.kwargs['app_id']] + + return initial + def form_valid(self, form): """Create the archive on valid form submission.""" repository = get_instance(form.cleaned_data['repository'])