Skip to content

Commit 1df8a96

Browse files
committed
Update downloads supernav page for Python install manager
1 parent e8ac397 commit 1df8a96

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

downloads/models.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,29 @@ def update_supernav():
158158
if not latest_python3:
159159
return
160160

161+
try:
162+
latest_pymanager = Release.objects.latest_pymanager()
163+
except Release.DoesNotExist:
164+
latest_pymanager = None
165+
161166
python_files = []
162167
for o in OS.objects.all():
163168
data = {
164169
'os': o,
165170
'python3': None,
171+
'pymanager': None,
166172
}
167173

168-
release_file = latest_python3.download_file_for_os(o.slug)
169-
if not release_file:
170-
continue
171-
data['python3'] = release_file
174+
data['python3'] = latest_python3.download_file_for_os(o.slug)
175+
if latest_pymanager:
176+
data['pymanager'] = latest_pymanager.download_file_for_os(o.slug)
172177

173178
python_files.append(data)
174179

175180
if not python_files:
176181
return
177182

178-
if not all(f['python3'] for f in python_files):
183+
if not all(f['python3'] or f['pymanager'] for f in python_files):
179184
# We have a latest Python release, different OSes, but don't have release
180185
# files for the release, so return early.
181186
return
@@ -287,6 +292,7 @@ def purge_fastly_download_pages(sender, instance, **kwargs):
287292
purge_url('/downloads/feed.rss')
288293
purge_url('/downloads/latest/python2/')
289294
purge_url('/downloads/latest/python3/')
295+
purge_url('/downloads/latest/pymanager/')
290296
purge_url('/downloads/macos/')
291297
purge_url('/downloads/source/')
292298
purge_url('/downloads/windows/')
@@ -308,9 +314,7 @@ def update_download_supernav_and_boxes(sender, instance, **kwargs):
308314
return
309315

310316
if instance.is_published:
311-
# Supernav only has download buttons for Python 3.
312-
if instance.version == instance.PYTHON3:
313-
update_supernav()
317+
update_supernav()
314318
update_download_landing_sources_box()
315319
update_homepage_download_box()
316320

downloads/tests/test_models.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..models import Release
1+
from ..models import Release, ReleaseFile
22
from .base import BaseDownloadTests
33

44

@@ -95,3 +95,51 @@ def test_is_version_at_least_with_invalid_name(self):
9595
self.assertFalse(invalid_release.is_version_at_least_3_5)
9696
self.assertFalse(invalid_release.is_version_at_least_3_9)
9797
self.assertFalse(invalid_release.is_version_at_least_3_14)
98+
99+
def test_update_supernav(self):
100+
from ..models import update_supernav
101+
from boxes.models import Box
102+
103+
release = Release.objects.create(
104+
name='Python install manager 25.0',
105+
version=Release.PYMANAGER,
106+
)
107+
108+
for os, url in [
109+
(self.windows, 'python-3.10-windows.msi'),
110+
(self.osx, 'python-3.10-macos.pkg'),
111+
(self.linux, 'python-3.10-linux.tar.gz'),
112+
]:
113+
ReleaseFile.objects.create(
114+
os=os,
115+
release=self.python_3,
116+
name='Python 3.10',
117+
url='/ftp/python/{}'.format(url),
118+
download_butter=True,
119+
)
120+
121+
update_supernav()
122+
123+
content = Box.get(label='download-sources').content
124+
self.assertIn('class="download-os-windows"', content)
125+
self.assertNotIn('pymanager-25.0.msix', content)
126+
self.assertIn('python-3.10-windows.msi', content)
127+
self.assertIn('class="download-os-macos"', content)
128+
self.assertIn('python-3.10-macos.pkg', content)
129+
self.assertIn('class="download-os-linux"', content)
130+
self.assertIn('python-3.10-linux.tar.gz', content)
131+
132+
ReleaseFile.objects.create(
133+
os=self.windows,
134+
release=release,
135+
name='MSIX',
136+
url='/ftp/python/pymanager/pymanager-25.0.msix',
137+
download_button=True,
138+
)
139+
140+
update_supernav()
141+
142+
content = Box.get(label='download-sources').content
143+
self.assertIn('class="download-os-windows"', content)
144+
self.assertIn('pymanager-25.0.msix', content)
145+
self.assertIn('python-3.10-windows.msi', content)

templates/downloads/supernav.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ <h4>Download for {{ data.os.name }}</h4>
1010

1111
{% if data.pymanager %}
1212
<p><a class="button" href="{{ data.pymanager.url }}">Python install manager</a></p>
13+
{% if data.python3 %}
1314
<p>Or get the standalone installer for <a class="button" href="{{ data.python3.url }}">{{ data.python3.release.name }}</a></p>
14-
{% else %}
15+
{% endif %}
16+
{% elif data.python3 %}
1517
<p>
1618
<a class="button" href="{{ data.python3.url }}">{{ data.python3.release.name }}</a>
1719
</p>

0 commit comments

Comments
 (0)