Add floating window for new threads
New threads get a floating window just like new replies have. This only pops up on the board detail view. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -2,9 +2,9 @@ from typing import Any, Dict
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model, get_user
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db.models import Q
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.http.request import QueryDict
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic import edit
|
||||
@@ -22,6 +22,7 @@ __all__ = (
|
||||
"BanSuccessView",
|
||||
"BannedView",
|
||||
"BoardView",
|
||||
"PostCreateView",
|
||||
"PostView",
|
||||
"PostSuccessView",
|
||||
"ReplyCreateView",
|
||||
@@ -77,9 +78,8 @@ class CreateView(edit.CreateView):
|
||||
return super(CreateView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class BoardView(CreateView):
|
||||
model = Post
|
||||
form_class = PostForm
|
||||
class BoardView(TemplateView):
|
||||
model = Board
|
||||
slug_field = "url"
|
||||
slug_url_kwarg = "url"
|
||||
template_name = "board/board_detail.html"
|
||||
@@ -92,6 +92,10 @@ class BoardView(CreateView):
|
||||
)
|
||||
return super(BoardView, self).get(request, *args, **kwargs)
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.board = get_object_or_404(Board, url=kwargs["url"])
|
||||
return super(BoardView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
page = self.kwargs["page"]
|
||||
|
||||
@@ -114,6 +118,33 @@ class BoardView(CreateView):
|
||||
return super(BoardView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
class PostCreateView(CreateView):
|
||||
model = Post
|
||||
form_class = PostForm
|
||||
slug_field = "url"
|
||||
slug_url_kwarg = "url"
|
||||
template_name = "board/post_create_view.html"
|
||||
|
||||
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
|
||||
return kwargs
|
||||
|
||||
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()
|
||||
|
||||
|
||||
class ReplyCreateView(CreateView):
|
||||
model = Post
|
||||
form_class = ReplyForm
|
||||
@@ -141,10 +172,14 @@ class ReplyCreateView(CreateView):
|
||||
kwargs["user"] = self.request.user
|
||||
return kwargs
|
||||
|
||||
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()
|
||||
|
||||
class PostView(CreateView):
|
||||
|
||||
class PostView(TemplateView):
|
||||
model = Post
|
||||
form_class = ReplyForm
|
||||
slug_field = "url"
|
||||
slug_url_kwarg = "url"
|
||||
|
||||
@@ -158,13 +193,10 @@ class PostView(CreateView):
|
||||
|
||||
return super(PostView, self).get_context_data(**kwargs)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(PostView, self).get_form_kwargs()
|
||||
post_id = self.kwargs["id"]
|
||||
post = get_object_or_404(Post, id=post_id)
|
||||
kwargs["op"] = post
|
||||
kwargs["user"] = self.request.user
|
||||
return kwargs
|
||||
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)
|
||||
|
||||
|
||||
class PostSuccessView(TemplateView):
|
||||
|
||||
Reference in New Issue
Block a user