Skip to content

Commit d2bf63d

Browse files
committed
feat: get children component count
1 parent c31707e commit d2bf63d

File tree

1 file changed

+23
-0
lines changed
  • openedx_learning/apps/authoring/publishing

1 file changed

+23
-0
lines changed

openedx_learning/apps/authoring/publishing/api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"get_entities_in_container",
8080
"contains_unpublished_changes",
8181
"get_containers_with_entity",
82+
"get_container_children_count",
8283
]
8384

8485

@@ -1086,3 +1087,25 @@ def get_containers_with_entity(
10861087
# publishable_entity__draft__version__containerversion__entity_list__in=lists
10871088
# )
10881089
return qs
1090+
1091+
1092+
def get_container_children_count(
1093+
container: Container,
1094+
*,
1095+
published: bool,
1096+
):
1097+
"""
1098+
[ 🛑 UNSTABLE ]
1099+
Get the count of entities in the current draft or published version of the given container.
1100+
1101+
Args:
1102+
container: The Container, e.g. returned by `get_container()`
1103+
published: `True` if we want the published version of the container, or
1104+
`False` for the draft version.
1105+
"""
1106+
assert isinstance(container, Container)
1107+
container_version = container.versioning.published if published else container.versioning.draft
1108+
if container_version is None:
1109+
raise ContainerVersion.DoesNotExist # This container has not been published yet, or has been deleted.
1110+
assert isinstance(container_version, ContainerVersion)
1111+
return container_version.entity_list.entitylistrow_set.count()

0 commit comments

Comments
 (0)