From 81c0ec3f682ebc3311d28fda18660b21d126fa8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=86=D0=B2=D0=B0=D0=BD=20=D0=9D=D1=94=D0=B4=D1=94=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=96=D1=86=D0=B5=D0=B2?= Date: Thu, 30 May 2024 13:02:41 +0300 Subject: [PATCH] chore: add fixme's --- lms/djangoapps/discussion/signals/handlers.py | 1 + lms/djangoapps/discussion/tasks.py | 1 + .../offline_mode/utils/assets_management.py | 6 ++++-- .../offline_mode/utils/html_manipulator.py | 2 ++ .../offline_mode/utils/xblock_helpers.py | 6 +++--- lms/djangoapps/offline_mode/views.py | 15 ++++++++++++++- .../html_block/mobile_api_module.py | 4 +++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/discussion/signals/handlers.py b/lms/djangoapps/discussion/signals/handlers.py index 719e32b3ceaf..4927bf7fe0a0 100644 --- a/lms/djangoapps/discussion/signals/handlers.py +++ b/lms/djangoapps/discussion/signals/handlers.py @@ -52,6 +52,7 @@ def update_discussions_on_course_publish(sender, course_key, **kwargs): # pylin import pdb; pdb.set_trace() request = generate_request_with_service_user() + # FIXME: Change the block id to the actual block id result = get_xblock_view_response(request, 'block-v1:new+123+new+type@problem+block@f7693d5dde094f65a28485582125936d', 'student_view') print(result) diff --git a/lms/djangoapps/discussion/tasks.py b/lms/djangoapps/discussion/tasks.py index 23af89888134..f3f14aaa117f 100644 --- a/lms/djangoapps/discussion/tasks.py +++ b/lms/djangoapps/discussion/tasks.py @@ -262,6 +262,7 @@ def _build_message_context(context, notification_type='forum_comment'): # lint- 'comment_username': comment_author.username, 'post_link': post_link, 'push_notification_extra_context': { + 'course_id': str(context['course_id']), 'notification_type': notification_type, 'topic_id': context.get('thread_commentable_id', ''), 'thread_id': context['thread_id'], diff --git a/lms/djangoapps/offline_mode/utils/assets_management.py b/lms/djangoapps/offline_mode/utils/assets_management.py index 2950764bb6f2..2d8bc57f904e 100644 --- a/lms/djangoapps/offline_mode/utils/assets_management.py +++ b/lms/djangoapps/offline_mode/utils/assets_management.py @@ -38,7 +38,7 @@ def save_asset_file(xblock, path, filename): pass else: base_path = base_storage_path(xblock) - default_storage.save(f'{base_path}assets/{filename}', ContentFile(content)) + default_storage.save(f'{base_path}assets/{filename}', ContentFile(content)) # FIXME: change to os.path.join def remove_old_files(xblock): @@ -55,6 +55,7 @@ def remove_old_files(xblock): # Define the paths to the specific items to delete asset_path = os.path.join(base_path, 'asset') index_file_path = os.path.join(base_path, 'index.html') + # FIXME: change filename to block_id or move to constants offline_zip_path = os.path.join(base_path, 'offline_content.zip') # Delete the 'asset' directory if it exists @@ -88,7 +89,7 @@ def is_offline_content_present(xblock): """ try: base_path = base_storage_path(xblock) - + # FIXME: change filename to block_id or move to constants # Define the path to the 'offline_content.zip' file offline_zip_path = os.path.join(base_path, 'offline_content.zip') @@ -116,4 +117,5 @@ def base_storage_path(xblock): Returns: str: The constructed base storage path. """ + # FIXME: change to os.path.join? return '{loc.org}/{loc.course}/{loc.block_type}/{loc.block_id}/'.format(loc=xblock.location) diff --git a/lms/djangoapps/offline_mode/utils/html_manipulator.py b/lms/djangoapps/offline_mode/utils/html_manipulator.py index 18d3abfb2c00..cac6c31b1083 100644 --- a/lms/djangoapps/offline_mode/utils/html_manipulator.py +++ b/lms/djangoapps/offline_mode/utils/html_manipulator.py @@ -10,6 +10,7 @@ def __init__(self, xblock, html_data): self.xblock = xblock def _replace_mathjax_link(self): + # FIXME: version shouldn't be hardcoded mathjax_pattern = re.compile(r'src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js[^"]*"') return mathjax_pattern.sub('src="/static/mathjax/MathJax.js"', self.html_data) @@ -34,6 +35,7 @@ def _replace_iframe(self, soup): def _add_js_bridge(self, soup): script_tag = soup.new_tag('script') + # FIXME: this script should be loaded from a file script_tag.string = """ // JS bridge script function sendMessageToiOS(message) { diff --git a/lms/djangoapps/offline_mode/utils/xblock_helpers.py b/lms/djangoapps/offline_mode/utils/xblock_helpers.py index 5041a552c75e..a4a69073a546 100644 --- a/lms/djangoapps/offline_mode/utils/xblock_helpers.py +++ b/lms/djangoapps/offline_mode/utils/xblock_helpers.py @@ -14,7 +14,7 @@ User = get_user_model() -OFFLINE_SUPPORTED_XBLOCKS = ['html', 'problem'] +OFFLINE_SUPPORTED_XBLOCKS = ['html', 'problem'] # FIXME: move this to settings def is_offline_supported(xblock): @@ -22,7 +22,7 @@ def is_offline_supported(xblock): def is_modified(xblock): - file_path = f'{base_storage_path(xblock)}content_html.zip' + file_path = f'{base_storage_path(xblock)}content_html.zip' # FIXME: change filename, and change to os.path.join try: last_modified = default_storage.get_created_time(file_path) @@ -33,7 +33,7 @@ def is_modified(xblock): def generate_request_with_service_user(): - user = User.objects.get(email='edx@example.com') + user = User.objects.get(email='edx@example.com') # FIXME: Change this to a valid user request = HttpRequest() request.user = user # Set up the session diff --git a/lms/djangoapps/offline_mode/views.py b/lms/djangoapps/offline_mode/views.py index 9626fc4a332e..068baad47e34 100644 --- a/lms/djangoapps/offline_mode/views.py +++ b/lms/djangoapps/offline_mode/views.py @@ -1,9 +1,22 @@ +import os +from django.conf import settings +from django.core.files.storage import default_storage + +from opaque_keys.edx.keys import CourseKey +from rest_framework.response import Response from rest_framework.views import APIView +from lms.djangoapps.offline_mode.utils.assets_management import is_offline_content_present, save_asset_file +from lms.djangoapps.offline_mode.utils.xblock_helpers import is_offline_supported +from xmodule.modulestore.django import modulestore + + +from .file_management import save_asset_file, remove_old_files, base_storage_path from .tasks import generate_course_media class OfflineXBlockStatusInfoView(APIView): + # FIXME: Add docstring def get(self, request, course_id): course_key = CourseKey.from_string(course_id) @@ -21,7 +34,7 @@ def get(self, request, course_id): html_data = default_storage.url(offline_zip_path) if not html_data.startswith('http'): - html_data = f'{settings.LMS_ROOT_URL}{html_data}' + html_data = f'{settings.LMS_ROOT_URL}{html_data}' # FIXME: use os.path.join last_modified = default_storage.get_created_time(offline_zip_path) size = default_storage.size(offline_zip_path) diff --git a/openedx/features/_mobile_extensions/html_block/mobile_api_module.py b/openedx/features/_mobile_extensions/html_block/mobile_api_module.py index 3adfd261ee00..491948de532a 100644 --- a/openedx/features/_mobile_extensions/html_block/mobile_api_module.py +++ b/openedx/features/_mobile_extensions/html_block/mobile_api_module.py @@ -34,6 +34,7 @@ def update_info_api(self, html_data=None): self.remove_old_files(base_path) # Replace MathJax URL + # FIXME: version shouldn't be hardcoded mathjax_pattern = re.compile(r'src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js[^"]*"') data = mathjax_pattern.sub(self._replace_mathjax_link, html_data) @@ -72,6 +73,7 @@ def _replace_iframe(self, soup): def _add_js_bridge(self, soup): script_tag = soup.new_tag('script') + # FIXME: this script should be loaded from a file script_tag.string = """ // Function to send messages to iOS function sendMessageToiOS(message) { @@ -209,7 +211,7 @@ def student_view_data(self): html_data = default_storage.url(file_path) if not html_data.startswith('http'): - html_data = f'{settings.LMS_ROOT_URL}{html_data}' + html_data = f'{settings.LMS_ROOT_URL}{html_data}' # FIXME: use os.path.join last_modified = default_storage.get_created_time(file_path) size = default_storage.size(file_path)