Skip to content

Commit 93af375

Browse files
committed
move the ancestor info in between of csv and ignore the first ancestor
1 parent 03113e0 commit 93af375

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kolibri/core/logger/csv_export.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def get_cached_ancestors(content_id):
132132

133133

134134
def get_max_ancestor_depth():
135+
"""Returns one less than the maximum depth of the ancestors of all content nodes"""
135136
max_depth = 0
136137
content_ids = ContentSummaryLog.objects.values_list("content_id", flat=True)
137138
nodes = ContentNode.objects.filter(content_id__in=content_ids).only(
@@ -142,10 +143,11 @@ def get_max_ancestor_depth():
142143
# cache it here so the retireival while adding ancestors info into csv is faster
143144
add_content_to_cache(node.content_id, title=node.title, ancestors=ancestors)
144145
max_depth = max(max_depth, len(ancestors))
145-
return max_depth
146+
return max_depth - 1
146147

147148

148149
def add_ancestors_info(row, ancestors, max_depth):
150+
ancestors = ancestors[1:]
149151
row.update(
150152
{
151153
f"Topic level {level + 1}": ancestors[level]["title"]
@@ -239,7 +241,10 @@ def csv_file_generator(
239241
for i in range(get_max_ancestor_depth())
240242
]
241243

242-
header_labels += [label for _, label in topic_headers]
244+
content_id_index = header_labels.index(labels["content_id"])
245+
header_labels[content_id_index:content_id_index] = [
246+
label for _, label in topic_headers
247+
]
243248

244249
csv_file = open_csv_for_writing(filepath)
245250

0 commit comments

Comments
 (0)