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 <alekratz@gmail.com>
This commit is contained in:
2022-05-07 15:14:50 -07:00
parent daa2febb5d
commit 994e4904a6
3 changed files with 36 additions and 4 deletions

View File

@@ -19,6 +19,13 @@ hr {
font-size: small; font-size: small;
} }
/* Pagination */
.pagination {
margin: auto;
width: 50%;
text-align: center;
}
/* Posts */ /* Posts */
/*.post_body { }*/ /*.post_body { }*/
.post_image_info { .post_image_info {

View File

@@ -63,4 +63,22 @@
<hr /> <hr />
{% endfor %} {% endfor %}
{# Page footer #}
<div class="row pagination">
{% if current_page > 1 %}
<a href="/{{board.url}}/page/{{ current_page|add:"-1" }}">{% localize on %}Prev{% endlocalize %}</a>
{% endif %}
[
{% for page in pages %}
{% if current_page == page %}
<strong>{{page}}</strong>
{% else %}
<a href="page/{{page}}">{{page}}</a>
{% endif %}
{% endfor %}
]
{% if current_page < last_page %}
<a href="/{{board.url}}/page/{{ current_page|add:"1" }}">{% localize on %}Next{% endlocalize %}</a>
{% endif %}
</div>
{% endblock content %} {% endblock content %}

View File

@@ -55,17 +55,24 @@ class BoardView(CreatePostView):
template_name = "board/board_detail.html" template_name = "board/board_detail.html"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs["board"] = self.board
page = self.kwargs.get("page", 1) page = self.kwargs.get("page", 1)
if page not in range(1, self.board.max_pages + 1): if page not in range(1, self.board.max_pages + 1):
raise Http404() raise Http404()
start = (page - 1) * self.board.threads_per_page threads_per_page = self.board.threads_per_page
end = start + 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["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 kwargs["max_upload_size"] = settings.MAX_UPLOAD_SIZE
return super(BoardView, self).get_context_data(**kwargs) return super(BoardView, self).get_context_data(**kwargs)