mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
backups: Allow selecting a single app from URL when creating backup
Take app_id in a URL fragment and fill that as the default selected app in create backup form. This URL can be used in apps to create a backup link. Tests: - Visit /plinth/sys/backups/create/bepasty/. Only bepasty app will be selected. - Visit /plinth/sys/backups/create/foo/. No apps are selected. - Visit /plinth/sys/backups/create/. All apps are selected. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
3667e934f1
commit
8f2520b327
@ -110,9 +110,10 @@ class CreateArchiveForm(forms.Form):
|
|||||||
components = api.get_all_components_for_backup()
|
components = api.get_all_components_for_backup()
|
||||||
choices = _get_app_choices(components)
|
choices = _get_app_choices(components)
|
||||||
self.fields['selected_apps'].choices = choices
|
self.fields['selected_apps'].choices = choices
|
||||||
self.fields['selected_apps'].initial = [
|
if not self.initial or 'selected_apps' not in self.initial:
|
||||||
choice[0] for choice in choices
|
self.fields['selected_apps'].initial = [
|
||||||
]
|
choice[0] for choice in choices
|
||||||
|
]
|
||||||
self.fields['repository'].choices = _get_repository_choices()
|
self.fields['repository'].choices = _get_repository_choices()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,8 @@ urlpatterns = [
|
|||||||
re_path(r'^sys/backups/$', BackupsView.as_view(), name='index'),
|
re_path(r'^sys/backups/$', BackupsView.as_view(), name='index'),
|
||||||
re_path(r'^sys/backups/(?P<uuid>[^/]+)/schedule/$', ScheduleView.as_view(),
|
re_path(r'^sys/backups/(?P<uuid>[^/]+)/schedule/$', ScheduleView.as_view(),
|
||||||
name='schedule'),
|
name='schedule'),
|
||||||
re_path(r'^sys/backups/create/$', CreateArchiveView.as_view(),
|
re_path(r'^sys/backups/create/(?:(?P<app_id>[1-9a-z\-_]+)/)?$',
|
||||||
name='create'),
|
CreateArchiveView.as_view(), name='create'),
|
||||||
re_path(r'^sys/backups/(?P<uuid>[^/]+)/download/(?P<name>[^/]+)/$',
|
re_path(r'^sys/backups/(?P<uuid>[^/]+)/download/(?P<name>[^/]+)/$',
|
||||||
DownloadArchiveView.as_view(), name='download'),
|
DownloadArchiveView.as_view(), name='download'),
|
||||||
re_path(r'^sys/backups/(?P<uuid>[^/]+)/delete/(?P<name>[^/]+)/$',
|
re_path(r'^sys/backups/(?P<uuid>[^/]+)/delete/(?P<name>[^/]+)/$',
|
||||||
|
|||||||
@ -116,6 +116,14 @@ class CreateArchiveView(SuccessMessageMixin, FormView):
|
|||||||
context['title'] = _('Create a new backup')
|
context['title'] = _('Create a new backup')
|
||||||
return context
|
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):
|
def form_valid(self, form):
|
||||||
"""Create the archive on valid form submission."""
|
"""Create the archive on valid form submission."""
|
||||||
repository = get_instance(form.cleaned_data['repository'])
|
repository = get_instance(form.cleaned_data['repository'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user