-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: [AXM-355] add information about offline metadata to course blocks #2571
Changes from all commits
05deb31
4c24f3a
d7ff649
02d9f51
3abe52d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,16 @@ | |
Views for course info API | ||
""" | ||
|
||
import os | ||
import logging | ||
from typing import Dict, Optional, Union | ||
|
||
import django | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.core.files.storage import default_storage | ||
from opaque_keys import InvalidKeyError | ||
from opaque_keys.edx.keys import CourseKey | ||
from opaque_keys.edx.keys import CourseKey, UsageKey | ||
from rest_framework import generics, status | ||
from rest_framework.response import Response | ||
from rest_framework.reverse import reverse | ||
|
@@ -31,6 +34,9 @@ | |
from openedx.core.lib.api.view_utils import view_auth_classes | ||
from openedx.core.lib.xblock_utils import get_course_update_items | ||
from openedx.features.course_experience import ENABLE_COURSE_GOALS | ||
from openedx.features.offline_mode.assets_management import get_offline_block_content_path | ||
from openedx.features.offline_mode.toggles import is_offline_mode_enabled | ||
|
||
from ..decorators import mobile_course_access, mobile_view | ||
|
||
User = get_user_model() | ||
|
@@ -369,6 +375,8 @@ def list(self, request, **kwargs): # pylint: disable=W0221 | |
course_key, | ||
response.data['blocks'], | ||
) | ||
if api_version == 'v4' and is_offline_mode_enabled(course_key): | ||
self._extend_block_info_with_offline_data(response.data['blocks']) | ||
|
||
course_info_context = { | ||
'user': requested_user, | ||
|
@@ -426,3 +434,21 @@ def _extend_sequential_info_with_assignment_progress( | |
} | ||
} | ||
) | ||
|
||
@staticmethod | ||
def _extend_block_info_with_offline_data(blocks_info_data: Dict[str, Dict]) -> None: | ||
""" | ||
Extends block info with offline download data. | ||
|
||
If offline content is available for the block, adds the offline download data to the block info. | ||
""" | ||
for block_id, block_info in blocks_info_data.items(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we optimize it by filtering only for supported offline types? |
||
if offline_content_path := get_offline_block_content_path(usage_key=UsageKey.from_string(block_id)): | ||
file_url = os.path.join(settings.MEDIA_URL, offline_content_path) | ||
block_info.update({ | ||
'offline_download': { | ||
'file_url': file_url, | ||
'last_modified': default_storage.get_created_time(offline_content_path), | ||
'file_size': default_storage.size(offline_content_path) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,5 @@ | |
MATHJAX_CDN_URL = f'https://cdn.jsdelivr.net/npm/mathjax@{MATHJAX_VERSION}/MathJax.js' | ||
MATHJAX_STATIC_PATH = os.path.join('assets', 'js', f'MathJax-{MATHJAX_VERSION}.js') | ||
|
||
DEFAULT_OFFLINE_SUPPORTED_XBLOCKS = ['problem'] | ||
DEFAULT_OFFLINE_SUPPORTED_XBLOCKS = ['html'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it intendant or a merge conflict? |
||
OFFLINE_SUPPORTED_XBLOCKS = getattr(settings, 'OFFLINE_SUPPORTED_XBLOCKS', DEFAULT_OFFLINE_SUPPORTED_XBLOCKS) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to discuss this with somebody from AXIM: @GlugovGrGlib @NiedielnitsevIvan TBD