Skip to content

Commit

Permalink
Prioritise 64-bit downloads over 32-bit (#2311)
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
  • Loading branch information
hugovk and hugovk committed Feb 21, 2024
1 parent a4990b7 commit f3fa1fc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
34 changes: 34 additions & 0 deletions downloads/templatetags/download_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions templates/downloads/os_list.html
Original file line number Diff line number Diff line change
@@ -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 %}

Expand Down Expand Up @@ -45,7 +46,7 @@ <h2>Stable Releases</h2>
{% endif %}
{% endif %}
<ul>
{% for f in r.files.all %}
{% for f in r.files.all|sort_windows %}
<li>Download <a href="{{ f.url }}">{{ f.name }}</a></li>
{% empty %}
<li>No files for this release.</li>
Expand All @@ -63,7 +64,7 @@ <h2>Pre-releases</h2>
<li>
<a href="{{ r.get_absolute_url }}">{{ r.name }} - {{ r.release_date|date }}</a>
<ul>
{% for f in r.files.all %}
{% for f in r.files.all|sort_windows %}
<li>Download <a href="{{ f.url }}">{{ f.name }}</a></li>
{% empty %}
<li>No files for this release.</li>
Expand Down
3 changes: 2 additions & 1 deletion templates/downloads/release_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load sitetree %}
{% load has_sigstore_materials from download_tags %}
{% load has_sbom from download_tags %}
{% load sort_windows from download_tags %}

{% block body_attributes %}class="python downloads"{% endblock %}

Expand Down Expand Up @@ -60,7 +61,7 @@ <h1 class="page-title">Files</h1>
</tr>
</thead>
<tbody>
{% for f in release_files %}
{% for f in release_files|sort_windows %}
<tr>
<td><a href="{{ f.url }}">{{ f.name }}</a></td>
<td>{{ f.os.name }}</td>
Expand Down

0 comments on commit f3fa1fc

Please sign in to comment.