Backups: show free disk space on upload+restore page

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Michael Pimmer authored and James Valleroy committed 2018-11-17 09:00:36 -05:00
1 parent 8cc74bd203
commit d4d5c15566
4 files changed
+46 -19

No files matched your search

@@ -32,7 +32,10 @@
You can choose the apps you wish to import after uploading a backup file.
{% endblocktrans %}
</p>
<br />
<div class="alert alert-info" role="alert">
{% trans "Free disk space" %}: {{ free_space }}<br />
{% trans "Make sure the uploaded file is smaller than that." %}
</div>
<form class="form" enctype="multipart/form-data" method="post">
{% csrf_token %}
+12 -1
View File
@@ -21,6 +21,7 @@ Views for the backups app.
from datetime import datetime
import gzip
from io import BytesIO
import logging
import mimetypes
import os
import tempfile
@@ -36,12 +37,15 @@ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from django.views.generic import View, FormView, TemplateView
from plinth.modules import backups
from plinth import actions
from plinth.errors import PlinthError
from plinth.modules import backups, storage
from . import api, forms, SESSION_PATH_VARIABLE
from .decorators import delete_tmp_backup_file
logger = logging.getLogger(__name__)
subsubmenu = [{
'url': reverse_lazy('backups:index'),
'text': ugettext_lazy('Backups')
@@ -142,6 +146,13 @@ class UploadArchiveView(SuccessMessageMixin, FormView):
context = super().get_context_data(**kwargs)
context['title'] = _('Upload and restore a backup file')
context['subsubmenu'] = subsubmenu
try:
disk_info = storage.get_disk_info('/', self.request)
except (PlinthError, PermissionError):
logger.error('Error getting information about root partition.')
else:
context['free_space'] = storage.format_bytes(
disk_info["free_bytes"])
return context
def form_valid(self, form):