From f13ad07ecb958da23565985daaed6853a0dae255 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Wed, 5 Feb 2020 23:19:28 +0530 Subject: [PATCH] backups: Add optional field - Name Signed-off-by: Joseph Nuthalapati [sunil: Perform validation for name field] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/modules/backups/forms.py | 4 ++++ plinth/modules/backups/views.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plinth/modules/backups/forms.py b/plinth/modules/backups/forms.py index 8ff0393a4..79aabd12f 100644 --- a/plinth/modules/backups/forms.py +++ b/plinth/modules/backups/forms.py @@ -48,6 +48,10 @@ def _get_repository_choices(): class CreateArchiveForm(forms.Form): repository = forms.ChoiceField() + name = forms.RegexField( + label=_('Name'), + help_text=_('(Optional) Set a name for this backup archive'), + regex=r'^[^{}/]*$', required=False, strip=True) selected_apps = forms.MultipleChoiceField( label=_('Included apps'), help_text=_('Apps to include in the backup'), widget=forms.CheckboxSelectMultiple) diff --git a/plinth/modules/backups/views.py b/plinth/modules/backups/views.py index 66d1915bf..4dc6d3bf9 100644 --- a/plinth/modules/backups/views.py +++ b/plinth/modules/backups/views.py @@ -66,7 +66,8 @@ class CreateArchiveView(SuccessMessageMixin, FormView): if repository.flags.get('mountable'): repository.mount() - name = datetime.now().strftime('%Y-%m-%d:%H:%M') + name = form.cleaned_data['name'] or datetime.now().strftime( + '%Y-%m-%d:%H:%M') selected_apps = form.cleaned_data['selected_apps'] repository.create_archive(name, selected_apps) return super().form_valid(form)