Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use manifest.json files to download collections #436

Merged
merged 9 commits into from
Jul 14, 2022
Next Next commit
Use manifest.json files to download collections
  • Loading branch information
danigm committed Jul 14, 2022
commit ed1fdb1ce95a245b8011eb2b0bb3d956cb0f3573
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