2022-07-12 19:28:20 -07:00
|
|
|
import functools
|
2022-06-23 16:03:09 -07:00
|
|
|
from typing import Any, Dict
|
2022-05-04 21:14:00 -07:00
|
|
|
from django.conf import settings
|
2022-07-12 19:28:20 -07:00
|
|
|
from django.contrib.auth import get_user
|
2022-06-23 16:03:09 -07:00
|
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
2022-06-23 18:16:00 -07:00
|
|
|
from django.db.models import Q
|
2022-05-03 18:02:04 -07:00
|
|
|
from django.http import Http404, HttpResponseRedirect
|
2022-06-28 23:55:44 -07:00
|
|
|
from django.http.request import QueryDict
|
2022-06-20 15:26:35 -07:00
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
|
from django.views.generic.base import TemplateView
|
2022-07-17 16:59:23 -07:00
|
|
|
from django.views.generic import detail, edit, list
|
2022-06-14 14:56:50 -07:00
|
|
|
from django.urls import reverse, reverse_lazy
|
2022-06-21 16:59:32 -07:00
|
|
|
from django.utils import timezone
|
2022-06-28 21:37:45 -07:00
|
|
|
|
|
|
|
|
from guardian.shortcuts import get_objects_for_user
|
|
|
|
|
|
2022-06-30 16:21:36 -07:00
|
|
|
from board.forms import *
|
2022-07-13 23:01:51 -07:00
|
|
|
from board.models import Ban, BanTemplate, Board, NewsPost, Post, Report
|
2022-06-24 16:50:46 -07:00
|
|
|
from board.utils import *
|
2022-05-03 18:02:04 -07:00
|
|
|
|
2022-06-23 16:03:09 -07:00
|
|
|
__all__ = (
|
2022-07-17 15:08:33 -07:00
|
|
|
"ActionSuccessView",
|
2022-06-23 16:03:09 -07:00
|
|
|
"BanCreateView",
|
|
|
|
|
"BanSuccessView",
|
|
|
|
|
"BannedView",
|
|
|
|
|
"BoardView",
|
2022-07-13 23:01:51 -07:00
|
|
|
"NewsListView",
|
2022-06-28 23:55:44 -07:00
|
|
|
"PostCreateView",
|
2022-06-30 16:21:36 -07:00
|
|
|
"PostModifyView",
|
2022-06-30 18:16:08 -07:00
|
|
|
"PostModifySuccessView",
|
2022-06-23 16:03:09 -07:00
|
|
|
"PostView",
|
2022-06-25 20:42:10 -07:00
|
|
|
"PostSuccessView",
|
2022-07-13 15:19:20 -07:00
|
|
|
"PostDeleteView",
|
2022-07-17 16:59:23 -07:00
|
|
|
"PostWipeView",
|
2022-06-25 20:42:10 -07:00
|
|
|
"ReplyCreateView",
|
2022-06-23 16:03:09 -07:00
|
|
|
"ReportView",
|
|
|
|
|
)
|
2022-05-03 18:02:04 -07:00
|
|
|
|
|
|
|
|
|
2022-06-30 18:16:08 -07:00
|
|
|
def can_modify(user):
|
|
|
|
|
if not user:
|
|
|
|
|
return False
|
|
|
|
|
# TODO add more permissions as required
|
2022-07-12 19:28:20 -07:00
|
|
|
return (
|
|
|
|
|
user.has_perm("board.set_sticky")
|
|
|
|
|
or user.has_perm("board.set_bump")
|
|
|
|
|
or user.has_perm("board.set_lock")
|
|
|
|
|
)
|
2022-06-30 18:16:08 -07:00
|
|
|
|
|
|
|
|
|
2022-07-17 15:08:33 -07:00
|
|
|
class ActionSuccessView(TemplateView):
|
|
|
|
|
template_name = "board/action_success.html"
|
|
|
|
|
message = "Action completed."
|
|
|
|
|
window_timeout = 0
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
|
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
context["message"] = self.message
|
|
|
|
|
context["window_timeout"] = self.window_timeout
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
2022-06-20 15:26:35 -07:00
|
|
|
class BannedView(TemplateView):
|
|
|
|
|
template_name = "board/banned.html"
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
context = super(TemplateView, self).get_context_data(**kwargs)
|
|
|
|
|
ip = get_client_ip(self.request)
|
|
|
|
|
bans = get_ip_bans(ip)
|
2022-06-21 16:59:32 -07:00
|
|
|
|
|
|
|
|
now = timezone.now()
|
2022-06-26 20:27:42 -07:00
|
|
|
active_bans = [ban for ban in bans if not ban.expires or ban.expires > now]
|
2022-06-20 15:26:35 -07:00
|
|
|
context["bans"] = bans
|
2022-06-21 16:59:32 -07:00
|
|
|
context["active_bans"] = active_bans
|
2022-06-20 15:26:35 -07:00
|
|
|
context["ip"] = ip
|
2022-06-21 16:59:32 -07:00
|
|
|
|
2022-06-20 15:26:35 -07:00
|
|
|
return context
|
2022-05-03 18:02:04 -07:00
|
|
|
|
|
|
|
|
|
2022-07-12 19:28:20 -07:00
|
|
|
class BoardMixin:
|
|
|
|
|
@functools.cached_property
|
|
|
|
|
def board(self) -> Board:
|
|
|
|
|
return get_object_or_404(Board, url=self.kwargs["url"]) # type: ignore
|
|
|
|
|
|
|
|
|
|
|
2022-07-19 18:59:25 -07:00
|
|
|
class NewsSnippetMixin:
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
context["news"] = NewsPost.objects.order_by("-id")[:3]
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
2022-07-12 19:28:20 -07:00
|
|
|
class CreateView(BoardMixin, edit.CreateView):
|
2022-05-07 13:24:43 -07:00
|
|
|
"""
|
2022-06-24 16:50:46 -07:00
|
|
|
Helper class that sets a few variables for posts and check against bans.
|
|
|
|
|
This should not be used by itself.
|
2022-05-07 13:24:43 -07:00
|
|
|
|
|
|
|
|
This class sets the following variables on GET and POST:
|
|
|
|
|
* self.board
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
2022-06-24 16:50:46 -07:00
|
|
|
kwargs = super(CreateView, self).get_form_kwargs()
|
2022-05-07 13:24:43 -07:00
|
|
|
kwargs["board"] = self.board
|
|
|
|
|
kwargs["ip"] = get_client_ip(self.request)
|
|
|
|
|
return kwargs
|
|
|
|
|
|
2022-06-20 15:26:35 -07:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
2022-06-24 16:50:46 -07:00
|
|
|
# Check for bans
|
2022-06-21 16:59:32 -07:00
|
|
|
ip = get_client_ip(request)
|
2022-06-24 16:50:46 -07:00
|
|
|
if request.method == "POST" and is_banned(ip, self.board):
|
|
|
|
|
return HttpResponseRedirect(reverse("board:banned"))
|
|
|
|
|
else:
|
|
|
|
|
return super(CreateView, self).dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
2022-07-19 18:59:25 -07:00
|
|
|
class BoardView(NewsSnippetMixin, BoardMixin, TemplateView):
|
2022-05-03 18:02:04 -07:00
|
|
|
template_name = "board/board_detail.html"
|
|
|
|
|
|
2022-05-07 16:31:32 -07:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
# If the page isn't set, then redirect to the /page/1 url
|
|
|
|
|
if "page" not in kwargs:
|
|
|
|
|
return HttpResponseRedirect(
|
|
|
|
|
reverse("board:board_detail", kwargs={"url": kwargs["url"], "page": 1})
|
|
|
|
|
)
|
|
|
|
|
return super(BoardView, self).get(request, *args, **kwargs)
|
|
|
|
|
|
2022-05-03 18:02:04 -07:00
|
|
|
def get_context_data(self, **kwargs):
|
2022-05-07 16:31:32 -07:00
|
|
|
page = self.kwargs["page"]
|
2022-05-03 18:02:04 -07:00
|
|
|
|
2022-05-07 13:24:43 -07:00
|
|
|
if page not in range(1, self.board.max_pages + 1):
|
2022-05-03 18:02:04 -07:00
|
|
|
raise Http404()
|
|
|
|
|
|
2022-05-07 15:14:50 -07:00
|
|
|
threads_per_page = self.board.threads_per_page
|
|
|
|
|
start = (page - 1) * threads_per_page
|
|
|
|
|
end = start + threads_per_page
|
|
|
|
|
thread_count = self.board.threads.count()
|
|
|
|
|
last_page = (thread_count // threads_per_page) + 1
|
|
|
|
|
|
|
|
|
|
kwargs["board"] = self.board
|
2022-06-30 16:21:36 -07:00
|
|
|
kwargs["threads"] = self.board.threads.order_by("-sticky", "-last_bump")[
|
|
|
|
|
start:end
|
|
|
|
|
]
|
2022-05-07 15:14:50 -07:00
|
|
|
kwargs["current_page"] = page
|
|
|
|
|
kwargs["pages"] = range(1, last_page + 1)
|
|
|
|
|
kwargs["last_page"] = last_page
|
2022-05-04 21:14:00 -07:00
|
|
|
kwargs["max_upload_size"] = settings.MAX_UPLOAD_SIZE
|
2022-05-03 18:02:04 -07:00
|
|
|
return super(BoardView, self).get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
2022-06-28 23:55:44 -07:00
|
|
|
class PostCreateView(CreateView):
|
|
|
|
|
model = Post
|
|
|
|
|
form_class = PostForm
|
2022-07-13 13:16:57 -07:00
|
|
|
template_name = "board/post_create.html"
|
2022-06-28 23:55:44 -07:00
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
context["board"] = self.board
|
|
|
|
|
context["max_upload_size"] = settings.MAX_UPLOAD_SIZE
|
|
|
|
|
context["capcodes"] = get_objects_for_user(
|
|
|
|
|
get_user(self.request), "board.use_capcode"
|
|
|
|
|
)
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
|
kwargs = super(PostCreateView, self).get_form_kwargs()
|
|
|
|
|
kwargs["user"] = self.request.user
|
2022-07-13 21:28:07 -07:00
|
|
|
if "user_token" not in self.request.session:
|
|
|
|
|
# Generate a user token
|
|
|
|
|
self.request.session["user_token"] = generate_user_token()
|
|
|
|
|
kwargs["user_token"] = self.request.session["user_token"]
|
2022-06-28 23:55:44 -07:00
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
def get_success_url(self) -> str:
|
|
|
|
|
query = QueryDict(mutable=True)
|
2022-07-17 15:08:33 -07:00
|
|
|
query["next"] = self.get_form().instance.get_absolute_url().split("#")[0]
|
|
|
|
|
print(query["next"])
|
2022-06-28 23:55:44 -07:00
|
|
|
return reverse("board:post_success") + "?" + query.urlencode()
|
|
|
|
|
|
|
|
|
|
|
2022-06-30 16:21:36 -07:00
|
|
|
class PostModifyView(PermissionRequiredMixin, edit.UpdateView):
|
|
|
|
|
model = Post
|
|
|
|
|
form_class = PostModifyForm
|
2022-07-13 13:16:57 -07:00
|
|
|
template_name = "board/post_modify.html"
|
2022-06-30 18:16:08 -07:00
|
|
|
success_url = reverse_lazy("board:post_modify_success")
|
2022-07-13 15:19:20 -07:00
|
|
|
raise_exception = True
|
2022-06-30 16:21:36 -07:00
|
|
|
|
|
|
|
|
def has_permission(self) -> bool:
|
2022-06-30 18:16:08 -07:00
|
|
|
return can_modify(self.request.user)
|
2022-06-30 16:21:36 -07:00
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
|
self.post_obj = get_object_or_404(Post, id=kwargs["pk"])
|
|
|
|
|
self.board = self.post_obj.board
|
|
|
|
|
return super(PostModifyView, self).dispatch(request, *args, **kwargs)
|
|
|
|
|
|
2022-06-30 18:16:08 -07:00
|
|
|
def get_form_kwargs(self) -> Dict[str, Any]:
|
|
|
|
|
kwargs = super(PostModifyView, self).get_form_kwargs()
|
|
|
|
|
kwargs["user"] = self.request.user
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
|
2022-07-17 15:08:33 -07:00
|
|
|
class PostModifySuccessView(PermissionRequiredMixin, ActionSuccessView):
|
2022-07-13 15:19:20 -07:00
|
|
|
raise_exception = True
|
2022-06-30 18:16:08 -07:00
|
|
|
|
|
|
|
|
def has_permission(self) -> bool:
|
|
|
|
|
return can_modify(self.request.user)
|
|
|
|
|
|
2022-06-30 16:21:36 -07:00
|
|
|
|
2022-06-25 20:42:10 -07:00
|
|
|
class ReplyCreateView(CreateView):
|
|
|
|
|
model = Post
|
|
|
|
|
form_class = ReplyForm
|
2022-07-13 13:16:57 -07:00
|
|
|
template_name = "board/reply_create.html"
|
2022-06-25 20:42:10 -07:00
|
|
|
success_url = reverse_lazy("board:post_success")
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
context["board"] = self.board
|
|
|
|
|
post_id = self.kwargs["id"]
|
|
|
|
|
context["post"] = get_object_or_404(Post, id=post_id)
|
|
|
|
|
context["max_upload_size"] = settings.MAX_UPLOAD_SIZE
|
2022-06-28 21:37:45 -07:00
|
|
|
context["capcodes"] = get_objects_for_user(
|
|
|
|
|
get_user(self.request), "board.use_capcode"
|
|
|
|
|
)
|
2022-06-25 20:42:10 -07:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
|
kwargs = super(ReplyCreateView, self).get_form_kwargs()
|
|
|
|
|
post_id = self.kwargs["id"]
|
|
|
|
|
post = get_object_or_404(Post, id=post_id)
|
|
|
|
|
kwargs["op"] = post
|
2022-06-28 21:37:45 -07:00
|
|
|
kwargs["user"] = self.request.user
|
2022-07-13 21:28:07 -07:00
|
|
|
if "user_token" not in self.request.session:
|
|
|
|
|
# Generate a user token
|
|
|
|
|
self.request.session["user_token"] = generate_user_token()
|
|
|
|
|
kwargs["user_token"] = self.request.session["user_token"]
|
2022-06-25 20:42:10 -07:00
|
|
|
return kwargs
|
|
|
|
|
|
2022-06-28 23:55:44 -07:00
|
|
|
def get_success_url(self) -> str:
|
|
|
|
|
query = QueryDict(mutable=True)
|
|
|
|
|
query["next"] = self.get_form().instance.get_absolute_url()
|
|
|
|
|
return reverse("board:post_success") + "?" + query.urlencode()
|
2022-06-25 20:42:10 -07:00
|
|
|
|
2022-06-28 23:55:44 -07:00
|
|
|
|
2022-07-19 18:59:25 -07:00
|
|
|
class PostView(NewsSnippetMixin, TemplateView):
|
2022-05-03 18:02:04 -07:00
|
|
|
template_name = "board/post_detail.html"
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2022-05-07 13:24:43 -07:00
|
|
|
kwargs["board"] = self.board
|
2022-05-03 18:02:04 -07:00
|
|
|
post_id = self.kwargs["id"]
|
2022-07-18 19:10:04 -07:00
|
|
|
post = get_object_or_404(Post, id=post_id)
|
|
|
|
|
kwargs["post"] = post
|
|
|
|
|
kwargs["replies"] = post.replies.all().order_by("id")
|
2022-05-04 21:14:00 -07:00
|
|
|
kwargs["max_upload_size"] = settings.MAX_UPLOAD_SIZE
|
2022-05-03 18:02:04 -07:00
|
|
|
return super(PostView, self).get_context_data(**kwargs)
|
|
|
|
|
|
2022-06-28 23:55:44 -07:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
|
# Set the board on this object
|
|
|
|
|
self.board = get_object_or_404(Board, url=kwargs["url"])
|
|
|
|
|
return super(PostView, self).dispatch(request, *args, **kwargs)
|
2022-06-14 14:56:50 -07:00
|
|
|
|
|
|
|
|
|
2022-07-17 15:08:33 -07:00
|
|
|
class PostSuccessView(ActionSuccessView):
|
2022-06-25 20:42:10 -07:00
|
|
|
template_name = "board/post_success.html"
|
2022-07-17 15:08:33 -07:00
|
|
|
window_timeout = settings.POST_WINDOW_CLOSE_TIMEOUT
|
2022-06-25 20:42:10 -07:00
|
|
|
|
|
|
|
|
|
2022-07-13 15:19:20 -07:00
|
|
|
class PostDeleteView(PermissionRequiredMixin, edit.DeleteView):
|
|
|
|
|
model = Post
|
|
|
|
|
form_class = PostDeleteForm
|
|
|
|
|
permission_required = ("board.delete_post",)
|
|
|
|
|
template_name = "board/post_confirm_delete.html"
|
|
|
|
|
success_url = reverse_lazy("board:post_delete_success")
|
|
|
|
|
raise_exception = True
|
|
|
|
|
|
2022-07-13 21:28:07 -07:00
|
|
|
def has_permission(self) -> bool:
|
|
|
|
|
object = self.get_object()
|
|
|
|
|
user_token = self.request.session.get("user_token", None)
|
|
|
|
|
return self.request.user.has_perm("board.delete_post") or (
|
|
|
|
|
user_token and object.user_token == user_token
|
|
|
|
|
)
|
|
|
|
|
|
2022-07-13 15:19:20 -07:00
|
|
|
def form_valid(self, form):
|
|
|
|
|
success_url = self.get_success_url()
|
|
|
|
|
if form["image_only"].value() != "0":
|
|
|
|
|
self.object.image.delete()
|
|
|
|
|
self.object.thumbnail.delete()
|
|
|
|
|
else:
|
|
|
|
|
self.object.delete()
|
|
|
|
|
return HttpResponseRedirect(success_url)
|
|
|
|
|
|
|
|
|
|
|
2022-07-17 16:59:23 -07:00
|
|
|
class PostWipeView(PermissionRequiredMixin, detail.SingleObjectMixin, TemplateView):
|
|
|
|
|
model = Post
|
|
|
|
|
permission_required = ("wipe_user",)
|
|
|
|
|
template_name = "board/post_wipe.html"
|
|
|
|
|
success_url = reverse_lazy("board:post_wipe_success")
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def all_posts(self):
|
2022-07-17 17:02:51 -07:00
|
|
|
return Post.objects.filter(
|
|
|
|
|
Q(ip=self.object.ip) | Q(user_token=self.object.user_token)
|
|
|
|
|
)
|
2022-07-17 16:59:23 -07:00
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
|
self.object = self.get_object()
|
|
|
|
|
return super(PostWipeView, self).dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
|
# Wipe user's posts
|
|
|
|
|
self.all_posts.delete()
|
|
|
|
|
# Success redirect
|
|
|
|
|
success_url = self.get_success_url()
|
|
|
|
|
return HttpResponseRedirect(success_url)
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
|
context = super(PostWipeView, self).get_context_data(**kwargs)
|
|
|
|
|
# context["all_posts"] = self.all_posts
|
|
|
|
|
# for some reason, {{all_posts.count}} does not seem to work in the template.
|
|
|
|
|
context["all_posts_count"] = self.all_posts.count()
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
|
return self.success_url
|
|
|
|
|
|
|
|
|
|
|
2022-06-24 16:50:46 -07:00
|
|
|
class ReportView(CreateView):
|
2022-06-14 14:56:50 -07:00
|
|
|
model = Report
|
|
|
|
|
form_class = ReportForm
|
|
|
|
|
success_url = reverse_lazy("board:report_success")
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def board_url(self) -> str:
|
|
|
|
|
return self.kwargs["url"]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def post_id(self) -> int:
|
|
|
|
|
return self.kwargs["id"]
|
|
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
|
kwargs = super(ReportView, self).get_form_kwargs()
|
|
|
|
|
post_id = self.kwargs["id"]
|
|
|
|
|
post = get_object_or_404(Post, id=post_id)
|
|
|
|
|
kwargs["op"] = post
|
|
|
|
|
return kwargs
|
2022-06-23 16:03:09 -07:00
|
|
|
|
|
|
|
|
|
2022-06-25 20:42:10 -07:00
|
|
|
class BanCreateView(PermissionRequiredMixin, edit.CreateView):
|
2022-06-23 16:03:09 -07:00
|
|
|
model = Ban
|
|
|
|
|
form_class = BanForm
|
2022-06-30 18:16:08 -07:00
|
|
|
permission_required = "board.add_ban"
|
2022-06-23 16:03:09 -07:00
|
|
|
success_url = reverse_lazy("board:ban_success")
|
2022-07-13 15:19:20 -07:00
|
|
|
raise_exception = True
|
2022-06-23 16:03:09 -07:00
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
|
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
context["board"] = self.board
|
|
|
|
|
context["post"] = self.post_obj
|
|
|
|
|
ip = self.post_obj.ip
|
|
|
|
|
now = timezone.now()
|
|
|
|
|
bans = [
|
|
|
|
|
ban
|
|
|
|
|
for ban in get_ip_bans(ip)
|
|
|
|
|
if ban.board == self.board or ban.board is None
|
|
|
|
|
]
|
|
|
|
|
context["previous_bans"] = [
|
2022-06-26 20:27:42 -07:00
|
|
|
ban for ban in bans if ban.expires and ban.expires < now
|
2022-06-23 16:03:09 -07:00
|
|
|
]
|
|
|
|
|
context["current_bans"] = [
|
2022-06-26 20:27:42 -07:00
|
|
|
ban for ban in bans if not ban.expires or ban.expires > now
|
2022-06-23 16:03:09 -07:00
|
|
|
]
|
2022-06-23 18:16:00 -07:00
|
|
|
context["templates"] = BanTemplate.objects.filter(
|
|
|
|
|
Q(board=self.board) | Q(board=None)
|
|
|
|
|
)
|
2022-06-23 16:03:09 -07:00
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
def get_form_kwargs(self) -> Dict[str, Any]:
|
2022-06-25 20:42:10 -07:00
|
|
|
kwargs = super(edit.CreateView, self).get_form_kwargs()
|
2022-06-23 16:03:09 -07:00
|
|
|
post_id = self.kwargs["id"]
|
|
|
|
|
post = get_object_or_404(Post, id=post_id)
|
|
|
|
|
kwargs["op"] = post
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
|
self.board = get_object_or_404(Board, url=kwargs["url"])
|
|
|
|
|
self.post_obj = get_object_or_404(Post, pk=kwargs["id"])
|
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
2022-07-17 15:08:33 -07:00
|
|
|
class BanSuccessView(PermissionRequiredMixin, ActionSuccessView):
|
2022-06-23 16:03:09 -07:00
|
|
|
permission_required = "ban.create"
|
2022-07-13 15:19:20 -07:00
|
|
|
raise_exception = True
|
2022-06-24 16:21:41 -07:00
|
|
|
|
2022-07-13 23:01:51 -07:00
|
|
|
|
|
|
|
|
class NewsListView(list.ListView):
|
|
|
|
|
model = NewsPost
|
|
|
|
|
template_name = "board/news_list.html"
|
|
|
|
|
ordering = ("-created",)
|