From 994e4904a607d2441d6064e08c96c89626e6e20b Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sat, 7 May 2022 15:14:50 -0700 Subject: [PATCH] Add page count and links to bottom of board view Current page shows up on the bottom of every board with next/prev links where applicable. Signed-off-by: Alek Ratzloff --- board/static/board/style.css | 7 +++++++ board/templates/board/board_detail.html | 18 ++++++++++++++++++ board/views.py | 15 +++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/board/static/board/style.css b/board/static/board/style.css index 5bd30a8..f0b7e1b 100644 --- a/board/static/board/style.css +++ b/board/static/board/style.css @@ -19,6 +19,13 @@ hr { font-size: small; } +/* Pagination */ +.pagination { + margin: auto; + width: 50%; + text-align: center; +} + /* Posts */ /*.post_body { }*/ .post_image_info { diff --git a/board/templates/board/board_detail.html b/board/templates/board/board_detail.html index 88d1f65..8affb5d 100644 --- a/board/templates/board/board_detail.html +++ b/board/templates/board/board_detail.html @@ -63,4 +63,22 @@
{% endfor %} +{# Page footer #} + {% endblock content %} \ No newline at end of file diff --git a/board/views.py b/board/views.py index 3dcf4b7..b10826a 100644 --- a/board/views.py +++ b/board/views.py @@ -55,17 +55,24 @@ class BoardView(CreatePostView): template_name = "board/board_detail.html" def get_context_data(self, **kwargs): - kwargs["board"] = self.board page = self.kwargs.get("page", 1) if page not in range(1, self.board.max_pages + 1): raise Http404() - start = (page - 1) * self.board.threads_per_page - end = start + self.board.threads_per_page + 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 kwargs["threads"] = self.board.threads.order_by("-last_bump")[start:end] - kwargs["page"] = page + kwargs["current_page"] = page + kwargs["pages"] = range(1, last_page + 1) + kwargs["last_page"] = last_page kwargs["max_upload_size"] = settings.MAX_UPLOAD_SIZE + return super(BoardView, self).get_context_data(**kwargs)