Skip to content

Commit 3e032ea

Browse files
committed
Use an endpoint for the release edit button that's only rendered for staff users
1 parent 48293a9 commit 3e032ea

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

downloads/views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,17 @@ def item_pubdate(self, item: Release) -> datetime | None:
267267
return timezone.make_aware(item.release_date)
268268
return item.release_date
269269
return None
270+
271+
272+
class ReleaseEditButton(TemplateView):
273+
"""Render the release edit button (shown only to staff users).
274+
275+
This endpoint is not cached, allowing the edit button to appear
276+
for staff users even when the release page itself is cached.
277+
"""
278+
template_name = "downloads/release_edit_button.html"
279+
280+
def get_context_data(self, **kwargs):
281+
context = super().get_context_data(**kwargs)
282+
context["release_pk"] = self.kwargs["pk"]
283+
return context

pydotorg/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.conf import settings
99

1010
from cms.views import custom_404
11+
from downloads.views import ReleaseEditButton
1112
from users.views import HoneypotSignupView, CustomPasswordChangeView
1213

1314
from . import views, urls_api
@@ -19,6 +20,7 @@
1920
path('', views.IndexView.as_view(), name='home'),
2021
re_path(r'^_health/?', views.health, name='health'),
2122
path('authenticated', views.AuthenticatedView.as_view(), name='authenticated'),
23+
path('release-edit-button/<int:pk>', ReleaseEditButton.as_view(), name='release_edit_button'),
2224
re_path(r'^humans.txt$', TemplateView.as_view(template_name='humans.txt', content_type='text/plain')),
2325
re_path(r'^robots.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
2426
re_path(r'^funding.json$', views.serve_funding_json, name='funding_json'),

templates/downloads/release_detail.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
{% block content %}
2424
<article class="text">
25-
{% if request.user.is_staff %}
26-
<a role="button" class="button" href="{% url 'admin:downloads_release_change' release.pk %}">Edit this release</a>
27-
{% endif %}
25+
<span data-html-include="{% url 'release_edit_button' release.pk %}"></span>
2826

2927
<header class="article-header">
3028
<h1 class="page-title">{{ release.name }}</h1>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% if request.user.is_staff %}
2+
<a role="button" class="button" href="{% url 'admin:downloads_release_change' release_pk %}">Edit this release</a>
3+
{% endif %}

0 commit comments

Comments
 (0)