Add configurable report and ban window timeouts.

On the success page for bans and reports, the window can now be
configured to close after N seconds if desired.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-06-24 16:21:41 -07:00
parent 412045e015
commit 36f73a2d31
5 changed files with 40 additions and 23 deletions

View File

@@ -5,7 +5,8 @@
{# Body #}
{% block content %}
<div class="row" id="message">
{% translate "A ban has been created. This window will close in 1 second." %}
{# We do not use pluralize filter for "seconds" because it's a pain to get it to translate. #}
{% blocktranslate %}A ban has been created. This window will close in {{window_timeout}} second(s).{% endblocktranslate %}
</div>
<script>
@@ -23,7 +24,7 @@ setTimeout(function() {
} else {
window.close();
}
}, 1000);
}, 1000 * {{window_timeout}});
</script>
{% endblock %}

View File

@@ -5,7 +5,8 @@
{# Body #}
{% block content %}
<div class="row" id="message">
{% translate "Post reported. This window will close in 1 second." %}
{# We do not use pluralize filter for "seconds" because it's a pain to get it to translate. #}
{% blocktranslate %}Post reported. This window will close in {{window_timeout}} second(s).{% endblocktranslate %}
</div>
<script>
@@ -23,7 +24,7 @@ setTimeout(function() {
} else {
window.close();
}
}, 1000);
}, 1000 * {{window_timeout}});
</script>
{% endblock %}

View File

@@ -1,32 +1,22 @@
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic.base import TemplateView
from board.views import *
app_name = "board"
urlpatterns = [
# Board views
path("<slug:url>/", BoardView.as_view(), name="board_detail"),
path("<slug:url>/page/<int:page>/", BoardView.as_view(), name="board_detail"),
path("<slug:url>/post/<int:id>/", PostView.as_view(), name="post_detail"),
# Reports
path("report/<slug:url>/<int:id>/", ReportView.as_view(), name="report_form"),
path(
"report/success/",
TemplateView.as_view(template_name="board/report_success.html"),
name="report_success",
),
path("report/success/", ReportSuccessView.as_view(), name="report_success"),
# Bans
path("ban/<slug:url>/<int:id>/", BanCreateView.as_view(), name="ban_create"),
path(
"ban/success/",
BanSuccessView.as_view(),
name="ban_success",
),
path(
"banned",
BannedView.as_view(),
name="banned",
),
path("ban/success/", BanSuccessView.as_view(), name="ban_success"),
path("banned", BannedView.as_view(), name="banned"),
]
# TODO - make this conditional so we can serve images up with whatever server we want
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@@ -19,6 +19,7 @@ __all__ = (
"BoardView",
"PostView",
"ReportView",
"ReportSuccessView",
)
@@ -145,9 +146,6 @@ class ReportView(CreatePostView):
form_class = ReportForm
success_url = reverse_lazy("board:report_success")
def get_context_data(self, **kwargs):
return super(ReportView, self).get_context_data(**kwargs)
@property
def board_url(self) -> str:
return self.kwargs["url"]
@@ -164,6 +162,15 @@ class ReportView(CreatePostView):
return kwargs
class ReportSuccessView(TemplateView):
template_name = "board/report_success.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["window_timeout"] = settings.REPORT_WINDOW_CLOSE_TIMEOUT
return context
class BanCreateView(PermissionRequiredMixin, CreateView):
model = Ban
form_class = BanForm
@@ -209,3 +216,8 @@ class BanCreateView(PermissionRequiredMixin, CreateView):
class BanSuccessView(PermissionRequiredMixin, TemplateView):
permission_required = "ban.create"
template_name = "board/ban_success.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["window_timeout"] = settings.BAN_WINDOW_CLOSE_TIMEOUT
return context