Skip to content

Commit

Permalink
Download manager: Set initial state on get status
Browse files Browse the repository at this point in the history
Otherwise the UI will attempt a new download in the next session after
the download is complete.

Helps #863
  • Loading branch information
manuq committed Oct 5, 2023
1 parent 12c1774 commit 5fc604c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kolibri_explore_plugin/collectionviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ def _set_empty_state(self):
self._enqueuing_timestamp = None
self._enqueued_timestamp = None

def is_state_unset(self):
return (
self._stage == DownloadStage.NOT_STARTED
and self._content_manifest is None
)

def start(self, manifest, user):
"""Start downloading a collection manifest."""
if self._stage != DownloadStage.NOT_STARTED:
Expand All @@ -265,6 +271,12 @@ def from_state(self, state):
self._tasks_completed = state["tasks_completed"]
self._tasks_previously_completed = state["tasks_previously_completed"]

logger.info(
f"Download state loaded for grade={grade} name={name}, "
+ f"stage={stage_name}"
)
logger.debug(f"Loaded download state: {state}")

def cancel(self):
if self._current_job_id is not None:
job_storage.cancel(self._current_job_id)
Expand Down Expand Up @@ -733,5 +745,13 @@ def cancel_download(request):
@api_view(["GET"])
def get_download_status(request):
"""Return the download status."""

saved_state = request.session.get("COLLECTIONS_STATE")
if (
_collection_download_manager.is_state_unset()
and saved_state is not None
):
_collection_download_manager.from_state(saved_state)

status = _collection_download_manager.get_status()
return Response({"status": status})

0 comments on commit 5fc604c

Please sign in to comment.