diff --git a/downloads/templatetags/download_tags.py b/downloads/templatetags/download_tags.py index 57004ccb4..c72f6d58c 100644 --- a/downloads/templatetags/download_tags.py +++ b/downloads/templatetags/download_tags.py @@ -19,3 +19,37 @@ def has_sigstore_materials(files): @register.filter def has_sbom(files): return any(f.sbom_spdx2_file for f in files) + + +@register.filter +def sort_windows(files): + if not files: + return files + + # Put Windows files in preferred order + files = list(files) + windows_files = [] + other_files = [] + for preferred in ( + 'Windows installer (64-bit)', + 'Windows installer (32-bit)', + 'Windows installer (ARM64)', + 'Windows help file', + 'Windows embeddable package (64-bit)', + 'Windows embeddable package (32-bit)', + 'Windows embeddable package (ARM64)', + ): + for file in files: + if file.name == preferred: + windows_files.append(file) + files.remove(file) + break + + # Then append any remaining Windows files + for file in files: + if file.name.startswith('Windows'): + windows_files.append(file) + else: + other_files.append(file) + + return other_files + windows_files diff --git a/templates/downloads/os_list.html b/templates/downloads/os_list.html index 67db5233f..1e0177dca 100644 --- a/templates/downloads/os_list.html +++ b/templates/downloads/os_list.html @@ -1,6 +1,7 @@ {% extends "downloads/base.html" %} {% load boxes %} {% load sitetree %} +{% load sort_windows from download_tags %} {% block body_attributes %}class="python download"{% endblock %} @@ -45,7 +46,7 @@

Stable Releases

{% endif %} {% endif %}