backups: Add optional field - Name

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Perform validation for name field]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati 2020-02-05 23:19:28 +05:30 committed by Sunil Mohan Adapa
parent 10924a1dca
commit f13ad07ecb
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 6 additions and 1 deletions

View File

@ -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)

View File

@ -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)