Fix Wagtail article publish regressions
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user