Skip to content

Commit

Permalink
feat: last update
Browse files Browse the repository at this point in the history
  • Loading branch information
vzadorozhnii committed May 20, 2024
1 parent 531e6b8 commit 30e2adf
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
4 changes: 4 additions & 0 deletions lms/djangoapps/discussion/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Signal handlers related to discussions.
"""

import six
import logging

from django.conf import settings
Expand All @@ -20,6 +21,7 @@
send_thread_created_notification,
send_response_endorsed_notifications
)
from lms.djangoapps.mobile_api.offline_mode.tasks import generate_course_media
from openedx.core.djangoapps.django_comment_common import signals
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
from openedx.core.djangoapps.theming.helpers import get_current_site
Expand All @@ -46,6 +48,8 @@ def update_discussions_on_course_publish(sender, course_key, **kwargs): # pylin
args=[context],
countdown=settings.DISCUSSION_SETTINGS['COURSE_PUBLISH_TASK_DELAY'],
)
# import pdb; pdb.set_trace()
generate_course_media(six.text_type(course_key))


@receiver(signals.comment_created)
Expand Down
14 changes: 11 additions & 3 deletions lms/djangoapps/mobile_api/offline_mode/signals.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import six
from django.dispatch import receiver
from openedx_events.content_authoring.signals import (
XBLOCK_CREATED,
XBLOCK_DELETED,
XBLOCK_DUPLICATED,
XBLOCK_UPDATED,
XBLOCK_PUBLISHED,
)

from xmodule.modulestore.django import SignalHandler

from .tasks import generate_course_media


@receiver(SignalHandler.course_published)
def hello_world(sender, course_key, **kwargs):
@receiver([XBLOCK_PUBLISHED])
def hello_world(**kwargs):
import pdb; pdb.set_trace()
generate_course_media.delay(six.text_type(course_key))
pass
# generate_course_media.delay(six.text_type(course_key))
8 changes: 5 additions & 3 deletions lms/djangoapps/mobile_api/offline_mode/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from opaque_keys.edx.keys import CourseKey

from xmodule.modulestore.django import modulestore
from .utils.xblock_helpers import generate_offline_content, xblock_view_handler, generate_request_with_service_user


@shared_task
def generate_course_media(course_id):
request = generate_request_with_service_user()
course_key = CourseKey.from_string(course_id)

for xblock_html in modulestore().get_items(course_key, qualifiers={'category': ['html', 'problem']}):
xblock_html.update_info_api()
for xblock in modulestore().get_items(course_key, qualifiers={'category': 'problem'}):
html_data = xblock_view_handler(request, xblock)
generate_offline_content(xblock, html_data)
41 changes: 23 additions & 18 deletions lms/djangoapps/mobile_api/offline_mode/utils/xblock_helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.http import HttpRequest

from xmodule.modulestore.django import modulestore

from .utils.html_manipulation import manipulate_html
from .utils.assets_management import save_asset_file, remove_old_files, base_storage_path
from .utils.zip_management import create_zip_file
from .html_manipulator import HtmlManipulator
from .assets_management import save_asset_file, remove_old_files, base_storage_path
from .zip_management import create_zip_file

User = get_user_model()

def is_modified(xblock):
file_path = f'{base_storage_path(xblock)}content_html.zip'
Expand All @@ -20,6 +23,12 @@ def is_modified(xblock):
return xblock.published_on > last_modified


def generate_request_with_service_user():
user = User.objects.get(email='[email protected]')
request = HttpRequest()
request.user = user
return request

def enclosing_sequence_for_gating_checks(block):
seq_tags = ['sequential']
if block.location.block_type in seq_tags:
Expand Down Expand Up @@ -49,8 +58,9 @@ def xblock_view_handler(request, xblock, check_if_enrolled=True, disable_staff_d
)
from openedx.core.lib.mobile_utils import is_request_from_mobile_app
from openedx.features.course_experience.utils import dates_banner_should_display
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.courseware.masquerade import is_masquerading_as_specific_student, setup_masquerade
from lms.djangoapps.courseware.views.views import get_optimization_flags_for_content
# from lms.djangoapps.courseware.views.views import get_optimization_flags_for_content
from lms.djangoapps.edxnotes.helpers import is_feature_enabled
from lms.djangoapps.courseware.date_summary import verified_upgrade_deadline_link
from common.djangoapps.edxmako.shortcuts import marketing_link, render_to_response, render_to_string
Expand Down Expand Up @@ -79,19 +89,14 @@ def xblock_view_handler(request, xblock, check_if_enrolled=True, disable_staff_d
staff_access,
)

UserActivity.record_user_activity(
request.user, usage_key.course_key, request=request, only_if_mobile_app=True
)

recheck_access = request.GET.get('recheck_access') == '1'
try:
block, _ = get_block_by_usage_id(
request,
str(course_key),
str(usage_key),
disable_staff_debug_info=disable_staff_debug_info,
course=course,
will_recheck_access=recheck_access,
will_recheck_access=False,
)
except:
return None
Expand All @@ -100,9 +105,9 @@ def xblock_view_handler(request, xblock, check_if_enrolled=True, disable_staff_d
student_view_context['show_bookmark_button'] = request.GET.get('show_bookmark_button', '0') == '1'
student_view_context['show_title'] = request.GET.get('show_title', '1') == '1'

is_learning_mfe = is_request_from_learning_mfe(request)
student_view_context['hide_access_error_blocks'] = is_learning_mfe and recheck_access
is_mobile_app = is_request_from_mobile_app(request)
# is_learning_mfe = is_request_from_learning_mfe(request)
student_view_context['hide_access_error_blocks'] = False
is_mobile_app = True
student_view_context['is_mobile_app'] = is_mobile_app

enable_completion_on_view_service = False
Expand All @@ -116,7 +121,7 @@ def xblock_view_handler(request, xblock, check_if_enrolled=True, disable_staff_d

missed_deadlines, missed_gated_content = dates_banner_should_display(course_key, request.user)
fragment = block.render('student_view', context=student_view_context)
optimization_flags = get_optimization_flags_for_content(block, fragment)
# optimization_flags = get_optimization_flags_for_content(block, fragment)

context = {
'fragment': fragment,
Expand All @@ -141,7 +146,7 @@ def xblock_view_handler(request, xblock, check_if_enrolled=True, disable_staff_d
'is_mobile_app': is_mobile_app,
'render_course_wide_assets': True,

**optimization_flags,
# **optimization_flags,
}
return render_to_string('courseware/courseware-chromeless.html', context)

Expand All @@ -152,8 +157,8 @@ def generate_offline_content(xblock, html_data):

base_path = base_storage_path(xblock)
remove_old_files(base_path)
html_manipulator = HtmlManipulator(xblock, html_data)
updated_html = html_manipulator.process_html()

manipulated_html = manipulate_html(html_data, lambda path, filename: save_asset_file(xblock, path, filename))

default_storage.save(f'{base_path}index.html', ContentFile(manipulated_html))
default_storage.save(f'{base_path}index.html', ContentFile(updated_html))
create_zip_file(base_path, 'content_html.zip')
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def _add_js_bridge(self, soup):
const originalAjax = $.ajax;
$.ajax = function(options) {
sendMessageToiOS(options)
sendMessageToiOS(JSON.stringify(options))
sendMessageToAndroid(options)
sendMessageToAndroid(JSON.stringify(options))
console.log(options, JSON.stringify(options))
Expand Down

0 comments on commit 30e2adf

Please sign in to comment.