Skip to content
Open
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
14 changes: 14 additions & 0 deletions downloads/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions pydotorg/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/<int:pk>', 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'),
Expand Down
4 changes: 1 addition & 3 deletions templates/downloads/release_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

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

<header class="article-header">
<h1 class="page-title">{{ release.name }}</h1>
Expand Down
3 changes: 3 additions & 0 deletions templates/downloads/release_edit_button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% if request.user.is_staff %}
<a role="button" class="button" href="{% url 'admin:downloads_release_change' release_pk %}">Edit this release</a>
{% endif %}