diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -6,6 +6,7 @@ import time import math import re from django.core.cache import cache +from django.core.paginator import Paginator from django.db import models from django.http import Http404 @@ -126,28 +127,12 @@ class PostManager(models.Manager): threads = threads.filter(archived=archived).order_by(order_by) if page != ALL_PAGES: - thread_count = threads.count() - - if page < self._get_page_count(thread_count): - start_thread = page * settings.THREADS_PER_PAGE - end_thread = min(start_thread + settings.THREADS_PER_PAGE, - thread_count) - threads = threads[start_thread:end_thread] + threads = Paginator(threads, settings.THREADS_PER_PAGE).page( + page).object_list return threads # TODO Move this method to thread manager - def get_thread_page_count(self, tag=None, archived=False): - if tag: - threads = Thread.objects.filter(tags=tag) - else: - threads = Thread.objects.all() - - threads = threads.filter(archived=archived) - - return self._get_page_count(threads.count()) - - # TODO Move this method to thread manager def _delete_old_threads(self): """ Preserves maximum thread count. If there are too many threads, @@ -180,13 +165,6 @@ class PostManager(models.Manager): referenced_post.last_edit_time = post.pub_time referenced_post.save() - def _get_page_count(self, thread_count): - """ - Get number of pages that will be needed for all threads - """ - - return int(math.ceil(thread_count / float(settings.THREADS_PER_PAGE))) - def get_posts_per_day(self): """ Get average count of posts per day for the last 7 days diff --git a/boards/templates/boards/archive.html b/boards/templates/boards/archive.html --- a/boards/templates/boards/archive.html +++ b/boards/templates/boards/archive.html @@ -6,23 +6,23 @@ {% load static %} {% block head %} -