backups: Show error when there are no disks available to add repo

When there are no additional disks available, don't show an empty drop down
for disks and throw an error when submitting. Instead make it clear that no
additional disks are available and that is why repository can't be created.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-08-29 15:51:41 -07:00 committed by James Valleroy
parent 1d031c97f1
commit d9d9c8167f
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -247,6 +247,16 @@ class AddRepositoryView(SuccessMessageMixin, FormView):
template_name = 'backups_add_repository.html'
success_url = reverse_lazy('backups:index')
def get(self, request, *args, **kwargs):
"""If there are no disks available for adding, throw error."""
if not forms.get_disk_choices():
messages.error(
request,
_('No additional disks available to add a repository.'))
return redirect(reverse_lazy('backups:index'))
return super().get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
"""Return additional context for rendering the template."""
context = super().get_context_data(**kwargs)