diff --git a/downloads/views.py b/downloads/views.py index 41e8839ff..a5f049984 100644 --- a/downloads/views.py +++ b/downloads/views.py @@ -267,3 +267,17 @@ def item_pubdate(self, item: Release) -> datetime | None: return timezone.make_aware(item.release_date) return item.release_date return None + + +class ReleaseEditButton(TemplateView): + """Render the release edit button (shown only to staff users). + + This endpoint is not cached, allowing the edit button to appear + for staff users even when the release page itself is cached. + """ + template_name = "downloads/release_edit_button.html" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["release_pk"] = self.kwargs["pk"] + return context diff --git a/pydotorg/urls.py b/pydotorg/urls.py index 06da1ecb8..be51ab09a 100644 --- a/pydotorg/urls.py +++ b/pydotorg/urls.py @@ -8,6 +8,7 @@ from django.conf import settings from cms.views import custom_404 +from downloads.views import ReleaseEditButton from users.views import HoneypotSignupView, CustomPasswordChangeView from . import views, urls_api @@ -19,6 +20,7 @@ path('', views.IndexView.as_view(), name='home'), re_path(r'^_health/?', views.health, name='health'), path('authenticated', views.AuthenticatedView.as_view(), name='authenticated'), + path('release-edit-button/', ReleaseEditButton.as_view(), name='release_edit_button'), path('humans.txt', TemplateView.as_view(template_name='humans.txt', content_type='text/plain')), path('robots.txt', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')), path('funding.json', views.serve_funding_json, name='funding_json'), diff --git a/templates/downloads/release_detail.html b/templates/downloads/release_detail.html index a41393711..e57bcec2b 100644 --- a/templates/downloads/release_detail.html +++ b/templates/downloads/release_detail.html @@ -22,9 +22,7 @@ {% block content %}
- {% if request.user.is_staff %} - Edit this release - {% endif %} +

{{ release.name }}

diff --git a/templates/downloads/release_edit_button.html b/templates/downloads/release_edit_button.html new file mode 100644 index 000000000..38e45c0b0 --- /dev/null +++ b/templates/downloads/release_edit_button.html @@ -0,0 +1,3 @@ +{% if request.user.is_staff %} +Edit this release +{% endif %}