Skip to content

Commit

Permalink
Merge branch 'master' into all-thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmccall committed Jun 20, 2023
2 parents a0e21c1 + ea80102 commit 040384d
Show file tree
Hide file tree
Showing 22 changed files with 705 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 6.13.0
current_version = 6.16.0
commit = True
tag = True

Expand Down
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
extend-exclude =
build/,
static/,
dist/,
node_modules/,
kolibri_explore_plugin/vendor/
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ node_modules
# vscode files
.vscode/

# Compiled python modules
__pycache__/

# Built and cached files
kolibri_explore_plugin/apps/**/*.zip
kolibri_explore_plugin/welcomeScreen/
kolibri_explore_plugin/static/kolibri_explore_plugin*
kolibri_explore_plugin/static/build-info.json
kolibri_explore_plugin/build/
kolibri_explore_plugin/__pycache__
build/
dist/
kolibri_explore_plugin.egg-info/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: (\.git/|\.tox/|\.venv/|build/|static/|dist/|node_modules/)
exclude: (\.git/|\.tox/|\.venv/|build/|static/|dist/|node_modules/|kolibri_explore_plugin/vendor/)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pre-commit = "==2.15.0"
twine = "*"
bumpversion = "*"
wheel = "*"
requests = "==2.27.1"

[requires]
python_version = "3"
188 changes: 61 additions & 127 deletions Pipfile.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion kolibri_explore_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__version__ = "6.13.0"
__version__ = "6.16.0"

default_app_config = "kolibri_explore_plugin.apps_config.ExploreConfig"

5 changes: 4 additions & 1 deletion kolibri_explore_plugin/assets/src/kolibriApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ class KolibriApi {
});
}

getContentById(id) {
getContentById(id, ignoreCache = false) {
if (ignoreCache && id in ContentNodeResource.cache) {
delete ContentNodeResource.cache[id];
}
return ContentNodeResource.fetchModel({ id: id });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ export function startContentDownload(channelId, contentId) {
type: TaskTypes.REMOTECONTENTIMPORT,
};

return TaskResource.startTask(taskParams).then(task => {
store.commit('manageContent/SET_CONTENT_DOWNLOAD_TASK', { channelId, contentId, task });
return _mapTaskStatusToDownloadState(task);
});
return TaskResource.startTask(taskParams)
.then(task => {
store.commit('manageContent/SET_CONTENT_DOWNLOAD_TASK', { channelId, contentId, task });
return _mapTaskStatusToDownloadState(task);
})
.catch(() => {
return constants.DownloadState.FAILED;
});
}

export function retryContentDownload(channelId, contentId) {
Expand Down
35 changes: 32 additions & 3 deletions kolibri_explore_plugin/assets/src/views/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
:nodes="nodes"
:mediaQuality="mediaQuality"
:cardColumns="cardColumns"
@nodeUpdated="onNodeUpdated"
>
<div>
<h4 class="text-muted">
<span class="font-weight-normal">
{{ nodes.length }} results for "{{ cleanedQuery }}"
{{ $tr('countedResults', {
count: nodes.length,
term: cleanedQuery,
action: groupVerb(kind)
}) }}
</span>
to {{ groupVerb(kind) }}
</h4>
</div>
</EkCardGrid>
Expand All @@ -74,7 +78,10 @@

<b-container v-if="resultChannels.length" class="pb-5 pt-3">
<h4 class="text-muted">
{{ resultChannels.length }} channels related to "{{ cleanedQuery }}"
{{ $tr('countedChannels', {
count: resultChannels.length,
term: cleanedQuery
}) }}
</h4>
<EkChannelCardGroup
variant="smallCard"
Expand Down Expand Up @@ -118,6 +125,7 @@
import _ from 'lodash';
import { mapMutations, mapState } from 'vuex';
import { utils, constants, responsiveMixin } from 'ek-components';
import { ContentNodeResource } from 'kolibri.resources';
import { searchChannelsOnce } from '../modules/topicsRoot/handlers';
import navigationMixin from '../mixins/navigationMixin';
Expand Down Expand Up @@ -283,10 +291,31 @@
this.query = words.join(' ');
this.$router.push({ params: { query: this.query } });
},
onNodeUpdated(nodeId) {
ContentNodeResource.fetchModel({ id: nodeId }).then(newNode => {
const index = this.searchResult[newNode.kind].results.findIndex(
node => node.id === newNode.id
);
if (index === -1) {
return;
}
// Add channel to new node, like the initial handler does:
const oldNode = this.searchResult[newNode.kind].results[index];
newNode.channel = oldNode.channel;
// Update the results reactively:
this.$set(this.searchResult[newNode.kind].results, index, newNode);
});
},
},
$trs: {
documentTitle: 'Library',
hideUnavailableLabel: 'Only downloaded items',
countedResults:
'{count} {count, plural, one {result} other {results}} for “{term}” to {action}',
countedChannels:
'{count} {count, plural, one {channel} other {channels}} related to “{term}”',
},
};
Expand Down
2 changes: 1 addition & 1 deletion kolibri_explore_plugin/collectionviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from kolibri.core.content.errors import InsufficientStorageSpaceError
from kolibri.core.content.models import ChannelMetadata
from kolibri.core.content.tasks import remotechannelimport
from kolibri.core.content.tasks import remotecontentimport
from kolibri.core.content.utils.content_manifest import ContentManifest
from kolibri.core.content.utils.content_manifest import (
ContentManifestParseError,
Expand All @@ -25,6 +24,7 @@
from .tasks import applyexternaltags
from .tasks import BACKGROUND_QUEUE
from .tasks import QUEUE
from .tasks import remotecontentimport

logger = logging.getLogger(__name__)

Expand Down
76 changes: 76 additions & 0 deletions kolibri_explore_plugin/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import logging

from django.core.management import call_command
from kolibri.core.content.tasks import get_status as get_content_task_status
from kolibri.core.content.tasks import RemoteChannelResourcesImportValidator
from kolibri.core.content.utils.paths import get_content_storage_remote_url
from kolibri.core.content.utils.resource_import import (
RemoteChannelResourceImportManager,
)
from kolibri.core.content.utils.resource_import import (
RemoteChannelUpdateManager,
)
from kolibri.core.content.utils.resource_import import (
RemoteResourceImportManagerBase,
)
from kolibri.core.serializers import HexOnlyUUIDField
from kolibri.core.tasks.decorators import register_task
from kolibri.core.tasks.job import State
Expand All @@ -10,6 +22,8 @@
from rest_framework.serializers import CharField
from rest_framework.serializers import ListField

from .vendor.file_transfer import FileDownload

logger = logging.getLogger(__name__)

QUEUE = "content"
Expand Down Expand Up @@ -51,3 +65,65 @@ def restart_failed_background_jobs():
f"Restarting failed background {job.func} job {job.job_id}"
)
job_storage.restart_job(job.job_id)


# Local remote resource import overrides to use vendored FileDownload.
class ExploreRemoteResourceImportManagerBase(RemoteResourceImportManagerBase):
def create_file_transfer(self, f, filename, dest):
url = get_content_storage_remote_url(filename, baseurl=self.baseurl)
return FileDownload(
url,
dest,
f["id"],
session=self.session,
cancel_check=self.is_cancelled,
timeout=self.timeout,
)


class ExploreRemoteChannelResourceImportManager(
ExploreRemoteResourceImportManagerBase, RemoteChannelResourceImportManager
):
pass


class ExploreRemoteChannelUpdateManager(
ExploreRemoteResourceImportManagerBase, RemoteChannelUpdateManager
):
pass


@register_task(
validator=RemoteChannelResourcesImportValidator,
track_progress=True,
cancellable=True,
permission_classes=[CanManageContent],
queue=QUEUE,
long_running=True,
status_fn=get_content_task_status,
)
def remotecontentimport(
channel_id,
baseurl=None,
peer_id=None,
node_ids=None,
exclude_node_ids=None,
update=False,
fail_on_error=False,
all_thumbnails=False,
):
manager_class = (
ExploreRemoteChannelUpdateManager
if update
else ExploreRemoteChannelResourceImportManager
)
manager = manager_class(
channel_id,
baseurl=baseurl,
peer_id=peer_id,
node_ids=node_ids,
exclude_node_ids=exclude_node_ids,
fail_on_error=fail_on_error,
all_thumbnails=all_thumbnails,
)
manager.run()
Empty file.
Loading

0 comments on commit 040384d

Please sign in to comment.