Skip to content

Commit

Permalink
Change calculate_included_languages to include them in order
Browse files Browse the repository at this point in the history
  • Loading branch information
jredrejo committed Dec 13, 2024
1 parent 682d1d2 commit 65743e2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kolibri/core/content/utils/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from itertools import groupby
from math import ceil

from django.db.models import Count
from django.db.models import Max
from django.db.models import Sum
from le_utils.constants import content_kinds
Expand Down Expand Up @@ -814,7 +815,14 @@ def calculate_included_languages(channel):
content_nodes = ContentNode.objects.filter(
channel_id=channel.id, available=True
).exclude(lang=None)
languages = content_nodes.order_by("lang").values_list("lang", flat=True).distinct()
languages = (
content_nodes.values("lang")
.annotate(count=Count("lang"))
.order_by("-count")
.values_list("lang", flat=True)
.distinct()
)
channel.included_languages.clear()
channel.included_languages.add(*list(languages))


Expand Down

0 comments on commit 65743e2

Please sign in to comment.