Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor DownloadLatestPython3x into DownloadLatestPython3
  • Loading branch information
hugovk committed Nov 24, 2025
commit c580bb537d8daa090d9a0d7f2ad86073e57fdb38
2 changes: 1 addition & 1 deletion downloads/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
urlpatterns = [
re_path(r'latest/python2/?$', views.DownloadLatestPython2.as_view(), name='download_latest_python2'),
re_path(r'latest/python3/?$', views.DownloadLatestPython3.as_view(), name='download_latest_python3'),
re_path(r'latest/python3\.(?P<minor>\d+)/?$', views.DownloadLatestPython3x.as_view(), name='download_latest_python3x'),
re_path(r'latest/python3\.(?P<minor>\d+)/?$', views.DownloadLatestPython3.as_view(), name='download_latest_python3x'),
re_path(r'latest/pymanager/?$', views.DownloadLatestPyManager.as_view(), name='download_latest_pymanager'),
re_path(r'latest/?$', views.DownloadLatestPython3.as_view(), name='download_latest_python3'),
path('operating-systems/', views.DownloadFullOSList.as_view(), name='download_full_os_list'),
Expand Down
25 changes: 3 additions & 22 deletions downloads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,21 @@ def get_redirect_url(self, **kwargs):


class DownloadLatestPython3(RedirectView):
""" Redirect to latest Python 3 release """
permanent = False

def get_redirect_url(self, **kwargs):
try:
latest_python3 = Release.objects.latest_python3()
except Release.DoesNotExist:
latest_python3 = None
"""Redirect to latest Python 3 release, optionally for a specific minor"""

if latest_python3:
return latest_python3.get_absolute_url()
else:
return reverse('download')


class DownloadLatestPython3x(RedirectView):
""" Redirect to latest Python 3.x release for a specific minor version """
permanent = False

def get_redirect_url(self, **kwargs):
minor_version = kwargs.get('minor')
if not minor_version:
return reverse('downloads:download')

try:
minor_version_int = int(minor_version)
minor_version_int = int(minor_version) if minor_version else None
latest_release = Release.objects.latest_python3(minor_version_int)
except (ValueError, Release.DoesNotExist):
latest_release = None

if latest_release:
return latest_release.get_absolute_url()
else:
return reverse('downloads:download')
return reverse("downloads:download")


class DownloadLatestPyManager(RedirectView):
Expand Down