Skip to content

Commit 176e499

Browse files
committed
sort like a hooman
1 parent 26738b3 commit 176e499

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

web/views.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import os
44
import json
5+
import string
56
from collections import OrderedDict
67
from django.views.decorators.cache import cache_page
78
from django.core.cache import cache
@@ -13,9 +14,24 @@
1314
from api.models import Pack, Song, Chart, ChartData
1415

1516
def natural_sort_key(text):
16-
"""order numbers naturally cause we are hoomans"""
17-
return [int(part) if part.isdigit() else part.lower()
18-
for part in re.split(r'(\d+)', text)]
17+
"""we are hoomans, lets sort like it"""
18+
# Determine top-level priority based on first character
19+
first_char = text.lstrip()[0] if text.strip() else ''
20+
if first_char in string.ascii_letters:
21+
priority = 2
22+
elif first_char.isdigit():
23+
priority = 1
24+
else:
25+
priority = 0
26+
27+
# Split text into alphanumeric chunks for natural sorting
28+
parts = re.split(r'(\d+)', text)
29+
normalized = [
30+
int(part) if part.isdigit() else part.lower()
31+
for part in parts
32+
]
33+
34+
return (priority, normalized)
1935

2036
def download_pack(request, pack_id):
2137
"""wrapper for downloading packs"""
@@ -278,6 +294,7 @@ def main(request):
278294
"""main pack list"""
279295
packs = list(Pack.objects.annotate(song_count=Count('songs')).order_by("name"))
280296
packs.sort(key=lambda pack: natural_sort_key(pack.name))
297+
281298
context = {
282299
"packs": packs
283300
}

0 commit comments

Comments
 (0)