From 7f6607a5132758c0a6ed995a519fb9a1ada619e6 Mon Sep 17 00:00:00 2001 From: rayzhou-bit Date: Thu, 28 Dec 2023 00:25:21 +0000 Subject: [PATCH 1/4] feat: include children info in xblock api --- .../xblock_storage_handlers/view_handlers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index f94b43d3e758..70c0126c29a7 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -180,7 +180,11 @@ def handle_xblock(request, usage_key_string=None): return JsonResponse(ancestor_info) # TODO: pass fields to get_block_info and only return those with modulestore().bulk_operations(usage_key.course_key): - response = get_block_info(get_xblock(usage_key, request.user)) + response = get_block_info( + get_xblock(usage_key, request.user), + include_child_info=True, + include_children_predicate=ALWAYS + ) if "customReadToken" in fields: parent_children = _get_block_parent_children(get_xblock(usage_key, request.user)) response.update(parent_children) @@ -824,8 +828,9 @@ def get_block_info( xblock, rewrite_static_links=True, include_ancestor_info=False, + include_child_info=False, include_publishing_info=False, - include_children_predicate=False, + include_children_predicate=NEVER, ): """ metadata, data, id representation of a leaf block fetcher. @@ -849,6 +854,7 @@ def get_block_info( data=data, metadata=own_metadata(xblock), include_ancestor_info=include_ancestor_info, + include_child_info=include_child_info, include_children_predicate=include_children_predicate ) if include_publishing_info: From 62e256b377cd70efbf6a78a58276229340ba73f2 Mon Sep 17 00:00:00 2001 From: rayzhou-bit Date: Tue, 2 Jan 2024 20:01:14 +0000 Subject: [PATCH 2/4] feat: only send child info for library_content --- .../xblock_storage_handlers/view_handlers.py | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index 70c0126c29a7..b218a2d0418f 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -180,11 +180,7 @@ def handle_xblock(request, usage_key_string=None): return JsonResponse(ancestor_info) # TODO: pass fields to get_block_info and only return those with modulestore().bulk_operations(usage_key.course_key): - response = get_block_info( - get_xblock(usage_key, request.user), - include_child_info=True, - include_children_predicate=ALWAYS - ) + response = get_block_info(get_xblock(usage_key, request.user)) if "customReadToken" in fields: parent_children = _get_block_parent_children(get_xblock(usage_key, request.user)) response.update(parent_children) @@ -837,6 +833,7 @@ def get_block_info( :param usage_key: A UsageKey """ with modulestore().bulk_operations(xblock.location.course_key): + category = getattr(xblock, "category", "") data = getattr(xblock, "data", "") if rewrite_static_links: data = replace_static_urls(data, None, course_id=xblock.location.course_key) @@ -848,15 +845,25 @@ def get_block_info( modulestore().get_course(xblock.location.course_key, depth=None) ) - # Note that children aren't being returned until we have a use case. - xblock_info = create_xblock_info( - xblock, - data=data, - metadata=own_metadata(xblock), - include_ancestor_info=include_ancestor_info, - include_child_info=include_child_info, - include_children_predicate=include_children_predicate - ) + # Note that children are returned for library_content blocks. + if category == "library_content": + xblock_info = create_xblock_info( + xblock, + data=data, + metadata=own_metadata(xblock), + include_ancestor_info=include_ancestor_info, + include_child_info=True, + include_children_predicate=ALWAYS + ) + else: + xblock_info = create_xblock_info( + xblock, + data=data, + metadata=own_metadata(xblock), + include_ancestor_info=include_ancestor_info, + include_child_info=include_child_info, + include_children_predicate=include_children_predicate + ) if include_publishing_info: add_container_page_publishing_info(xblock, xblock_info) From 3f6cb64cb64eb79f77796fa7e9d1617e53bdf129 Mon Sep 17 00:00:00 2001 From: rayzhou-bit Date: Wed, 3 Jan 2024 01:57:15 +0000 Subject: [PATCH 3/4] feat: childrenInfo field --- .../xblock_storage_handlers/view_handlers.py | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index b218a2d0418f..7add10b44d37 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -178,6 +178,16 @@ def handle_xblock(request, usage_key_string=None): xblock, is_concise=True ) return JsonResponse(ancestor_info) + elif "childrenInfo" in fields: + xblock = get_xblock(usage_key, request.user) + children_info = _create_xblock_child_info( + xblock, + course_outline=None, + graders=None, + include_children_predicate=ALWAYS, + is_concise=True + ) + return JsonResponse(children_info) # TODO: pass fields to get_block_info and only return those with modulestore().bulk_operations(usage_key.course_key): response = get_block_info(get_xblock(usage_key, request.user)) @@ -845,25 +855,14 @@ def get_block_info( modulestore().get_course(xblock.location.course_key, depth=None) ) - # Note that children are returned for library_content blocks. - if category == "library_content": - xblock_info = create_xblock_info( - xblock, - data=data, - metadata=own_metadata(xblock), - include_ancestor_info=include_ancestor_info, - include_child_info=True, - include_children_predicate=ALWAYS - ) - else: - xblock_info = create_xblock_info( - xblock, - data=data, - metadata=own_metadata(xblock), - include_ancestor_info=include_ancestor_info, - include_child_info=include_child_info, - include_children_predicate=include_children_predicate - ) + # Note that children aren't being returned until we have a use case. + xblock_info = create_xblock_info( + xblock, + data=data, + metadata=own_metadata(xblock), + include_ancestor_info=include_ancestor_info, + include_children_predicate=include_children_predicate + ) if include_publishing_info: add_container_page_publishing_info(xblock, xblock_info) From 1e188727409fa5a9afd38ca78e373a59f86a49ae Mon Sep 17 00:00:00 2001 From: rayzhou-bit Date: Wed, 3 Jan 2024 17:07:12 +0000 Subject: [PATCH 4/4] feat: remove unused lines --- .../contentstore/xblock_storage_handlers/view_handlers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index 7add10b44d37..e5dd276b5790 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -834,7 +834,6 @@ def get_block_info( xblock, rewrite_static_links=True, include_ancestor_info=False, - include_child_info=False, include_publishing_info=False, include_children_predicate=NEVER, ): @@ -843,7 +842,6 @@ def get_block_info( :param usage_key: A UsageKey """ with modulestore().bulk_operations(xblock.location.course_key): - category = getattr(xblock, "category", "") data = getattr(xblock, "data", "") if rewrite_static_links: data = replace_static_urls(data, None, course_id=xblock.location.course_key)