Skip to content

Commit

Permalink
Use manifest.json files to download collections
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Jul 8, 2022
1 parent 3d355ba commit fed0380
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
8 changes: 8 additions & 0 deletions kolibri_explore_plugin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
to the package install directory.
""",
},
"CONTENT_COLLECTIONS_PATH": {
"type": "string",
"default": "",
"description": """
Location where collections manifests are stored. Defaults
to the static/collections folder.
""",
},
"SHOW_AS_STANDALONE_CHANNEL": {
"type": "boolean",
"default": False,
Expand Down
28 changes: 19 additions & 9 deletions kolibri_explore_plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from django.views.generic.base import TemplateView
from django.views.generic.base import View
from kolibri.core.content.api import cache_forever
from kolibri.core.content.api import RemoteChannelViewSet
from kolibri.core.content.zip_wsgi import add_security_headers
from kolibri.core.content.zip_wsgi import get_embedded_file
from kolibri.core.decorators import cache_no_user_data
Expand All @@ -35,6 +34,13 @@
APPS_BUNDLE_PATHS.append(os.path.join(os.path.dirname(__file__), "apps"))


COLLECTION_PATHS = os.path.join(
os.path.dirname(__file__), "static", "collections"
)
if conf.OPTIONS["Explore"]["CONTENT_COLLECTIONS_PATH"]:
COLLECTION_PATHS = conf.OPTIONS["Explore"]["CONTENT_COLLECTIONS_PATH"]


@method_decorator(cache_no_user_data, name="dispatch")
class ExploreView(TemplateView):
template_name = "explore/explore.html"
Expand Down Expand Up @@ -199,20 +205,22 @@ def post(self, request):
data = json.loads(request.body)
collection = data.get("collection", "small")

token = self.COLLECTIONS[collection]["token"]

channel_viewset = RemoteChannelViewSet()
channels = channel_viewset._make_channel_endpoint_request(
identifier=token
collection_manifest = os.path.join(
COLLECTION_PATHS, f"{collection}.json"
)

job_ids = []
if not os.path.exists(collection_manifest):
raise Http404

manifest = {}
with open(collection_manifest) as f:
manifest = json.load(f)

job_ids = []
pid, _, _ = get_status()
for channel in channels:
for channel in manifest.get("channels", []):
task = {
"channel_id": channel["id"],
"channel_name": channel["name"],
"baseurl": self.BASE_URL,
"started_by_username": "endless",
"type": "REMOTEIMPORT",
Expand All @@ -223,6 +231,8 @@ def post(self, request):
_remoteimport,
task["channel_id"],
task["baseurl"],
node_ids=channel["include_node_ids"] or None,
exclude_node_ids=channel["exclude_node_ids"] or None,
extra_metadata=task,
track_progress=True,
cancellable=True,
Expand Down

0 comments on commit fed0380

Please sign in to comment.