From 47d1c0296eba5ee60b77b407a1b44530275c4858 Mon Sep 17 00:00:00 2001 From: Sagirov Eugeniy Date: Thu, 17 Oct 2024 14:07:17 +0300 Subject: [PATCH] refactor: updated container_embed_handler and added comments to container_chromeless.html --- .../contentstore/views/component.py | 27 +++++++++---------- cms/templates/container_chromeless.html | 25 +++++++++-------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index 11ce9657577d..5b6dd30ab844 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -146,32 +146,29 @@ def container_handler(request, usage_key_string): # pylint: disable=too-many-st @login_required def container_embed_handler(request, usage_key_string): # pylint: disable=too-many-statements """ - Returns an HttpResponse with HTML content for the container xBlock. - The returned HTML is a chromeless rendering of the xBlock. + Returns an HttpResponse with HTML content for the container XBlock. + The returned HTML is a chromeless rendering of the XBlock. GET html: returns the HTML page for editing a container json: not currently supported """ + # Avoiding a circular dependency from ..utils import get_container_handler_context - if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): - + try: + usage_key = UsageKey.from_string(usage_key_string) + except InvalidKeyError: # Raise Http404 on invalid 'usage_key_string' + return HttpResponseBadRequest() + with modulestore().bulk_operations(usage_key.course_key): try: - usage_key = UsageKey.from_string(usage_key_string) - except InvalidKeyError: # Raise Http404 on invalid 'usage_key_string' + course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key) + except ItemNotFoundError: raise Http404 # lint-amnesty, pylint: disable=raise-missing-from - with modulestore().bulk_operations(usage_key.course_key): - try: - course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key) - except ItemNotFoundError: - return HttpResponseBadRequest() - container_handler_context = get_container_handler_context(request, usage_key, course, xblock) - return render_to_response('container_chromeless.html', container_handler_context) - else: - return HttpResponseBadRequest("Only supports HTML requests") + container_handler_context = get_container_handler_context(request, usage_key, course, xblock) + return render_to_response('container_chromeless.html', container_handler_context) def get_component_templates(courselike, library=False): # lint-amnesty, pylint: disable=too-many-statements diff --git a/cms/templates/container_chromeless.html b/cms/templates/container_chromeless.html index 9f5c79ec9235..2fe821e49d5e 100644 --- a/cms/templates/container_chromeless.html +++ b/cms/templates/container_chromeless.html @@ -1,5 +1,10 @@ ## coding=utf-8 ## mako +## +## Studio view template for rendering the whole Unit in an iframe with +## XBlocks controls specifically for Authoring MFE. This template renders +## a chromeless version of a unit container without headers, footers, +## and a navigation bar. <%! main_css = "style-main-v1" %> @@ -93,21 +98,13 @@ <%static:include path="common/templates/image-modal.underscore" /> + ## The following stylesheets are included for studio-frontend debugging. + ## Remove this as part of studio frontend deprecation. + ## https://github.com/openedx/studio-frontend/issues/381 % if not settings.STUDIO_FRONTEND_CONTAINER_URL: % endif - - @@ -167,8 +164,6 @@ - - ##
@@ -194,6 +189,7 @@ + <%static:webpack entry="js/factories/container"> ContainerFactory( ${component_templates | n, dump_js_escaped_json}, @@ -209,6 +205,9 @@ ); + + ## Initialize MutationObserver and ResizeObserver to update the iframe size. + ## These are used to provide resize events for the Authoring MFE.