Enhancement: Sort groups during xc_get_live_categories in the order that they first appear in the channel list (lowest channel number)

This commit is contained in:
SergeantPanda 2025-10-25 09:47:39 -05:00
parent 2042274f10
commit 423c56f582

View file

@ -1712,6 +1712,7 @@ def xc_xmltv(request):
def xc_get_live_categories(user):
from django.db.models import Min
response = []
if user.user_level == 0:
@ -1722,7 +1723,7 @@ def xc_get_live_categories(user):
# No profile filtering - user sees all channel groups
channel_groups = ChannelGroup.objects.filter(
channels__isnull=False, channels__user_level__lte=user.user_level
).distinct().order_by(Lower("name"))
).distinct().annotate(min_channel_number=Min('channels__channel_number')).order_by('min_channel_number')
else:
# User has specific limited profiles assigned
filters = {
@ -1730,11 +1731,11 @@ def xc_get_live_categories(user):
"channels__user_level": 0,
"channels__channelprofilemembership__channel_profile__in": user.channel_profiles.all()
}
channel_groups = ChannelGroup.objects.filter(**filters).distinct().order_by(Lower("name"))
channel_groups = ChannelGroup.objects.filter(**filters).distinct().annotate(min_channel_number=Min('channels__channel_number')).order_by('min_channel_number')
else:
channel_groups = ChannelGroup.objects.filter(
channels__isnull=False, channels__user_level__lte=user.user_level
).distinct().order_by(Lower("name"))
).distinct().annotate(min_channel_number=Min('channels__channel_number')).order_by('min_channel_number')
for group in channel_groups:
response.append(