|
2 | 2 | import re |
3 | 3 | import os |
4 | 4 | import json |
| 5 | +import string |
5 | 6 | from collections import OrderedDict |
6 | 7 | from django.views.decorators.cache import cache_page |
7 | 8 | from django.core.cache import cache |
|
13 | 14 | from api.models import Pack, Song, Chart, ChartData |
14 | 15 |
|
15 | 16 | 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) |
19 | 35 |
|
20 | 36 | def download_pack(request, pack_id): |
21 | 37 | """wrapper for downloading packs""" |
@@ -278,6 +294,7 @@ def main(request): |
278 | 294 | """main pack list""" |
279 | 295 | packs = list(Pack.objects.annotate(song_count=Count('songs')).order_by("name")) |
280 | 296 | packs.sort(key=lambda pack: natural_sort_key(pack.name)) |
| 297 | + |
281 | 298 | context = { |
282 | 299 | "packs": packs |
283 | 300 | } |
|
0 commit comments