Skip to content

Commit

Permalink
Define explict preferred order for Windows files
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Sep 29, 2023
1 parent 6509e25 commit dadd924
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
46 changes: 26 additions & 20 deletions downloads/templatetags/download_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,34 @@ def has_sigstore_materials(files):


@register.filter
def prioritise_64bit_over_32bit(files):
def sort_windows(files):
if not files:
return files

# Put 64-bit files before 32-bit
new = []
previous = files[0]
for i, current in enumerate(files):
if i >= 1 and '(64-bit)' in current.name and '(32-bit)' in previous.name:
new.insert(-1, current)
# 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:
new.append(current)
previous = current
other_files.append(file)

# Put embeddable packages at the end
embeddable_packages = []
others = []

for file in new:
if file.name.startswith('Windows embeddable package'):
embeddable_packages.append(file)
else:
others.append(file)

return others + embeddable_packages
return other_files + windows_files
6 changes: 3 additions & 3 deletions templates/downloads/os_list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "downloads/base.html" %}
{% load boxes %}
{% load sitetree %}
{% load prioritise_64bit_over_32bit from download_tags %}
{% load sort_windows from download_tags %}

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

Expand Down Expand Up @@ -46,7 +46,7 @@ <h2>Stable Releases</h2>
{% endif %}
{% endif %}
<ul>
{% for f in r.files.all|prioritise_64bit_over_32bit %}
{% 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 @@ -64,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|prioritise_64bit_over_32bit %}
{% 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
4 changes: 2 additions & 2 deletions templates/downloads/release_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load boxes %}
{% load sitetree %}
{% load has_sigstore_materials from download_tags %}
{% load prioritise_64bit_over_32bit from download_tags %}
{% load sort_windows from download_tags %}

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

Expand Down Expand Up @@ -57,7 +57,7 @@ <h1 class="page-title">Files</h1>
</tr>
</thead>
<tbody>
{% for f in release_files|prioritise_64bit_over_32bit %}
{% 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 dadd924

Please sign in to comment.