Skip to content

Commit c580bb5

Browse files
committed
Refactor DownloadLatestPython3x into DownloadLatestPython3
1 parent 5df244b commit c580bb5

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

downloads/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
urlpatterns = [
66
re_path(r'latest/python2/?$', views.DownloadLatestPython2.as_view(), name='download_latest_python2'),
77
re_path(r'latest/python3/?$', views.DownloadLatestPython3.as_view(), name='download_latest_python3'),
8-
re_path(r'latest/python3\.(?P<minor>\d+)/?$', views.DownloadLatestPython3x.as_view(), name='download_latest_python3x'),
8+
re_path(r'latest/python3\.(?P<minor>\d+)/?$', views.DownloadLatestPython3.as_view(), name='download_latest_python3x'),
99
re_path(r'latest/pymanager/?$', views.DownloadLatestPyManager.as_view(), name='download_latest_pymanager'),
1010
re_path(r'latest/?$', views.DownloadLatestPython3.as_view(), name='download_latest_python3'),
1111
path('operating-systems/', views.DownloadFullOSList.as_view(), name='download_full_os_list'),

downloads/views.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,21 @@ def get_redirect_url(self, **kwargs):
3030

3131

3232
class DownloadLatestPython3(RedirectView):
33-
""" Redirect to latest Python 3 release """
34-
permanent = False
35-
36-
def get_redirect_url(self, **kwargs):
37-
try:
38-
latest_python3 = Release.objects.latest_python3()
39-
except Release.DoesNotExist:
40-
latest_python3 = None
33+
"""Redirect to latest Python 3 release, optionally for a specific minor"""
4134

42-
if latest_python3:
43-
return latest_python3.get_absolute_url()
44-
else:
45-
return reverse('download')
46-
47-
48-
class DownloadLatestPython3x(RedirectView):
49-
""" Redirect to latest Python 3.x release for a specific minor version """
5035
permanent = False
5136

5237
def get_redirect_url(self, **kwargs):
5338
minor_version = kwargs.get('minor')
54-
if not minor_version:
55-
return reverse('downloads:download')
56-
5739
try:
58-
minor_version_int = int(minor_version)
40+
minor_version_int = int(minor_version) if minor_version else None
5941
latest_release = Release.objects.latest_python3(minor_version_int)
6042
except (ValueError, Release.DoesNotExist):
6143
latest_release = None
6244

6345
if latest_release:
6446
return latest_release.get_absolute_url()
65-
else:
66-
return reverse('downloads:download')
47+
return reverse("downloads:download")
6748

6849

6950
class DownloadLatestPyManager(RedirectView):

0 commit comments

Comments
 (0)