diff --git a/cms/djangoapps/contentstore/views/block.py b/cms/djangoapps/contentstore/views/block.py index 1de45f716d..b57042085d 100644 --- a/cms/djangoapps/contentstore/views/block.py +++ b/cms/djangoapps/contentstore/views/block.py @@ -57,7 +57,7 @@ from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( ) from cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers import ( usage_key_with_run, - get_children_tags_count, + get_tags_count, ) @@ -245,10 +245,10 @@ def xblock_view_handler(request, usage_key_string, view_name): force_render = request.GET.get("force_render", None) - # Fetch tags of children components + # Fetch tags of xblock and children components tags_count_map = {} if not is_tagging_feature_disabled(): - tags_count_map = get_children_tags_count(xblock) + tags_count_map = get_tags_count(xblock, include_children=True) # Set up the context to be passed to each XBlock's render method. context = request.GET.dict() diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py index 7e589405a1..3afe9be813 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/xblock_helpers.py @@ -16,11 +16,19 @@ def usage_key_with_run(usage_key_string): return usage_key -def get_children_tags_count(xblock): +def get_tags_count(xblock, include_children=False): """ - Returns a map with tag count of each child + Returns a map with tag count of the `xblock` + + Use `include_children` to include each children on the query. """ - children = xblock.get_children() - child_usage_keys = [str(child.location) for child in children] - tags_count_query = ','.join(child_usage_keys) + query_list = [str(xblock.location)] + + if include_children: + children = xblock.get_children() + child_usage_keys = [str(child.location) for child in children] + query_list.extend(child_usage_keys) + + tags_count_query = ",".join(query_list) + return get_object_tag_counts(tags_count_query, count_implicit=True)