Add thread pruning for threads that pass the maximum page threshhold

Each board is allowed a number of threads per page, and a maximum number
of pages (default 10 for both). If a thread falls off the last page, it
is deleted.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-05-06 22:00:54 -07:00
parent e9585544d5
commit 27045c11c2
2 changed files with 24 additions and 14 deletions

View File

@@ -3,7 +3,6 @@ from django.http import Http404, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.views.generic import DetailView
from django.views.generic.edit import CreateView
from board.models import Post, Board
__all__ = ("BoardView", "PostView")
@@ -29,7 +28,6 @@ class BoardView(CreateView):
fields = ["subject", "name", "text", "image"]
slug_field = "url"
slug_url_kwarg = "url"
template_name = "board/board_detail.html"
def get_context_data(self, **kwargs):
@@ -38,13 +36,11 @@ class BoardView(CreateView):
kwargs["board"] = board
page = self.kwargs.get("page", 1)
# TODO - allow max number of pages to be specified per-board
if page not in range(1, 10 + 1):
if page not in range(1, board.max_pages + 1):
raise Http404()
PER_PAGE = 10
start = (page - 1) * PER_PAGE
end = start + PER_PAGE
start = (page - 1) * board.threads_per_page
end = start + board.threads_per_page
kwargs["threads"] = board.threads.order_by("-last_bump")[start:end]
kwargs["page"] = page
kwargs["max_upload_size"] = settings.MAX_UPLOAD_SIZE