Fix Wagtail article publish regressions
All checks were successful
CI / nightly-e2e (pull_request) Has been skipped
CI / deploy (pull_request) Has been skipped
CI / ci (pull_request) Successful in 1m17s
CI / pr-e2e (pull_request) Successful in 1m46s

This commit is contained in:
2026-03-15 16:53:49 +00:00
parent 15ef35e249
commit 1a0617fbd0
8 changed files with 161 additions and 34 deletions

View File

@@ -4,7 +4,6 @@ import logging
import requests as http_requests
from django.conf import settings
from django.contrib import messages
from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.db import IntegrityError
@@ -41,6 +40,11 @@ def _add_vary_header(response):
return response
def _comment_redirect(article: ArticlePage, *, approved: bool):
state = "approved" if approved else "pending"
return redirect(f"{article.url}?commented={state}")
def _verify_turnstile(token: str, ip: str) -> bool:
secret = getattr(settings, "TURNSTILE_SECRET_KEY", "")
if not secret:
@@ -201,7 +205,7 @@ class CommentCreateView(View):
return _add_vary_header(
render(request, "comments/_comment_success.html", {"message": "Comment posted!"})
)
return redirect(f"{article.url}?commented=1")
return _comment_redirect(article, approved=True)
# Turnstile verification
turnstile_ok = False
@@ -230,11 +234,7 @@ class CommentCreateView(View):
if _is_htmx(request):
return self._render_htmx_success(request, article, comment)
messages.success(
request,
"Comment posted!" if comment.is_approved else "Your comment is awaiting moderation",
)
return redirect(f"{article.url}?commented=1")
return _comment_redirect(article, approved=comment.is_approved)
if _is_htmx(request):
return self._render_htmx_error(request, article, form)