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 authored and James Valleroy committed 2019-09-07 12:53:17 -04:00
1 parent 1d031c97f1
commit d9d9c8167f
1 file changed
+10
+10
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)