diff --git a/kolibri/core/content/utils/settings.py b/kolibri/core/content/utils/settings.py index 01aa8b70b85..7f7a21a3394 100644 --- a/kolibri/core/content/utils/settings.py +++ b/kolibri/core/content/utils/settings.py @@ -43,7 +43,6 @@ def get_free_space_for_downloads(completed_size=0): from kolibri.core.device.utils import get_device_setting from kolibri.utils.conf import OPTIONS - from kolibri.utils.data import bytes_from_humans from kolibri.utils.system import get_free_space free_space = get_free_space(OPTIONS["Paths"]["CONTENT_DIR"]) @@ -51,10 +50,7 @@ def get_free_space_for_downloads(completed_size=0): # if a limit is set, subtract the total content storage size from the limit if get_device_setting("set_limit_for_autodownload"): # compute total space used by automatic and learner initiated downloads - # convert limit_for_autodownload from GB to bytes - auto_download_limit = bytes_from_humans( - str(get_device_setting("limit_for_autodownload") or "0") + "GB" - ) + auto_download_limit = get_device_setting("limit_for_autodownload") or 0 # returning smallest argument as to not exceed the space available on disk free_space = min(free_space, auto_download_limit - completed_size) diff --git a/kolibri/plugins/device/assets/src/views/DeviceSettingsPage/index.vue b/kolibri/plugins/device/assets/src/views/DeviceSettingsPage/index.vue index 969a2eeaad3..ee0d199b68b 100644 --- a/kolibri/plugins/device/assets/src/views/DeviceSettingsPage/index.vue +++ b/kolibri/plugins/device/assets/src/views/DeviceSettingsPage/index.vue @@ -215,15 +215,16 @@ >

0

- {{ freeSpace }} + {{ toGigabytes(freeSpace) }}

@@ -554,6 +556,14 @@ } return this.$tr('alertDisabledOptions'); }, + limitForAutodownloadInput: { + get() { + return this.toGigabytes(this.limitForAutodownload); + }, + set(value) { + this.limitForAutodownload = this.toBytes(value); + }, + }, }, created() { this.setDeviceURLs(); @@ -696,7 +706,7 @@ }, setFreeSpace() { return getFreeSpaceOnServer().then(({ freeSpace }) => { - this.freeSpace = parseInt(bytesForHumans(freeSpace).substring(0, 3)); + this.freeSpace = freeSpace; }); }, handleLandingPageChange(option) { @@ -872,6 +882,18 @@ } return ''; }, + updateLimitForAutodownload() { + this.limitForAutodownload = this.toBytes(this.limitForAutodownloadInput); + }, + updateLimitForAutodownloadInput() { + this.limitForAutodownloadInput = this.toGigabytes(this.limitForAutodownload); + }, + toBytes(gigabytes) { + return parseInt(Math.round(gigabytes * 10 ** 9)); + }, + toGigabytes(bytes) { + return parseInt(bytesForHumans(bytes).replace(/[^0-9.]/g, '')); + }, }, $trs: { browserDefaultLanguage: {