Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 31 additions & 0 deletions downloads/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ def test_download_release_detail(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 404)

def test_download_release_detail_not_superseded(self):
"""Test that latest releases and Python 2 do not show a superseded notice."""
for release in [self.python_3, self.python_3_8_20, self.release_275]:
with self.subTest(release=release.name):
url = reverse(
"download:download_release_detail",
kwargs={"release_slug": release.slug},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertNotIn("latest_in_series", response.context)
self.assertNotContains(response, "has been superseded by")

def test_download_release_detail_superseded(self):
"""Test that older releases show a superseded notice."""
tests = [
(self.python_3_10_18, self.python_3),
(self.python_3_8_19, self.python_3_8_20),
]
for old_release, latest_release in tests:
with self.subTest(release=old_release.name):
url = reverse(
"download:download_release_detail",
kwargs={"release_slug": old_release.slug},
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["latest_in_series"], latest_release)
self.assertContains(response, "has been superseded by")
self.assertContains(response, latest_release.name)

def test_download_os_list(self):
url = reverse('download:download_os_list', kwargs={'slug': self.linux.slug})
response = self.client.get(url)
Expand Down
12 changes: 12 additions & 0 deletions downloads/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

import re
from datetime import datetime

from django.db.models import Case, IntegerField, Prefetch, When
Expand Down Expand Up @@ -216,6 +217,17 @@ def get_context_data(self, **kwargs):
)
)

# Find the latest release in the feature series (such as 3.14.x)
# to show a "superseded by" notice on older releases
version = self.object.get_version()
if version and self.object.version == Release.PYTHON3:
match = re.match(r"^3\.(\d+)", version)
if match:
minor_version = int(match.group(1))
latest_in_series = Release.objects.latest_python3(minor_version)
if latest_in_series and latest_in_series.pk != self.object.pk:
context["latest_in_series"] = latest_in_series

return context


Expand Down
6 changes: 5 additions & 1 deletion templates/downloads/release_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
<h1 class="page-title">{{ release.name }}</h1>
</header>

<p><strong>Release Date:</strong> {{ release.release_date|date }}</p>
{% if latest_in_series %}
<p><strong>Note:</strong> {{ release.name }} has been superseded by <a href="{{ latest_in_series.get_absolute_url }}">{{ latest_in_series.name }}</a>.</p>
{% endif %}

<p><strong>Release date:</strong> {{ release.release_date|date }}</p>

{% if release.content.raw %}
{{ release.content.rendered|safe }}
Expand Down