Skip to content

Commit 7a8bd53

Browse files
authored
Update downloads supernav page for Python install manager (#2793)
1 parent e8ac397 commit 7a8bd53

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-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: 52 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,54 @@ 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+
is_latest=True,
107+
is_published=True,
108+
)
109+
110+
for os, slug in [
111+
(self.windows, 'python3.10-windows'),
112+
(self.osx, 'python3.10-macos'),
113+
(self.linux, 'python3.10-linux'),
114+
]:
115+
ReleaseFile.objects.create(
116+
os=os,
117+
release=self.python_3,
118+
slug=slug,
119+
name='Python 3.10',
120+
url='/ftp/python/{}.zip'.format(slug),
121+
download_button=True,
122+
)
123+
124+
update_supernav()
125+
126+
content = Box.objects.get(label='supernav-python-downloads').content.rendered
127+
self.assertIn('class="download-os-windows"', content)
128+
self.assertNotIn('pymanager-25.0.msix', content)
129+
self.assertIn('python3.10-windows.zip', content)
130+
self.assertIn('class="download-os-macos"', content)
131+
self.assertIn('python3.10-macos.zip', content)
132+
self.assertIn('class="download-os-linux"', content)
133+
self.assertIn('python3.10-linux.zip', content)
134+
135+
ReleaseFile.objects.create(
136+
os=self.windows,
137+
release=release,
138+
name='MSIX',
139+
url='/ftp/python/pymanager/pymanager-25.0.msix',
140+
download_button=True,
141+
)
142+
143+
update_supernav()
144+
145+
content = Box.objects.get(label='supernav-python-downloads').content.rendered
146+
self.assertIn('class="download-os-windows"', content)
147+
self.assertIn('pymanager-25.0.msix', content)
148+
self.assertIn('python3.10-windows.zip', 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)