Browse Source

Made thread pagination configurable

Rafał Pitoń 10 years ago
parent
commit
60d44a6362

+ 12 - 0
docs/developers/settings.rst

@@ -276,6 +276,12 @@ MISAGO_POSTING_MIDDLEWARES
 List of middleware classes participating in posting process.
 
 
+MISAGO_POSTS_PER_PAGE
+---------------------
+
+Controls number of posts displayed on thread page. Greater numbers can increase number of objects loaded into memory and thus depending on features enabled greatly increase memory usage.
+
+
 MISAGO_RANKING_LENGTH
 ---------------------
 
@@ -323,6 +329,12 @@ MISAGO_STOP_FORUM_SPAM_USE
 This settings allows you to decide wheter of not `Stop Forum Spam <http://www.stopforumspam.com/>`_ database should be used to validate IPs and emails during new users registrations.
 
 
+MISAGO_THREAD_TAIL
+------------------
+
+Defines minimal number of posts for threads last page. If number of posts on last page is smaller or equal to one specified in this setting, last page will be appended to previous page instead.
+
+
 MISAGO_THREAD_TYPES
 -------------------
 

+ 5 - 0
misago/conf/defaults.py

@@ -319,6 +319,11 @@ MISAGO_AVATARS_SIZES = (400, 200, 150, 100, 64, 50, 30, 20)
 MISAGO_AVATAR_SERVER_PATH = '/user-avatar'
 
 
+# Number of posts displayed on single thread page
+MISAGO_POSTS_PER_PAGE = 15
+MISAGO_THREAD_TAIL = 7
+
+
 # Controls max age in days of items that Misago has to process to make rankings
 # Used for active posters and most liked users lists
 # If your forum runs out of memory when trying to generate users rankings list

+ 7 - 6
misago/threads/goto.py

@@ -1,5 +1,6 @@
 from math import ceil
 
+from django.conf import settings
 from django.core.urlresolvers import reverse
 
 from misago.readtracker.threadstracker import make_read_aware
@@ -12,24 +13,24 @@ def posts_queryset(qs):
 
 
 def get_thread_pages(posts):
-    if posts <= 13:
+    if posts <= settings.MISAGO_POSTS_PER_PAGE + settings.MISAGO_THREAD_TAIL:
         return 1
 
-    thread_pages = posts / 10
-    thread_tail = posts - thread_pages * 10
-    if thread_tail and thread_tail > 3:
+    thread_pages = posts / settings.MISAGO_POSTS_PER_PAGE
+    thread_tail = posts - thread_pages * settings.MISAGO_POSTS_PER_PAGE
+    if thread_tail and thread_tail > settings.MISAGO_THREAD_TAIL:
         thread_pages += 1
     return thread_pages
 
 
 def get_post_page(posts, post_qs):
     post_no = post_qs.count()
-    if posts <= 13:
+    if posts <= settings.MISAGO_POSTS_PER_PAGE + settings.MISAGO_THREAD_TAIL:
         return 1
 
     thread_pages = get_thread_pages(posts)
 
-    post_page = int(ceil(float(post_no) / 10))
+    post_page = int(ceil(float(post_no) / settings.MISAGO_POSTS_PER_PAGE))
     if post_page > thread_pages:
         post_page = thread_pages
     return post_page

+ 4 - 1
misago/threads/views/generic/thread/view.py

@@ -1,3 +1,4 @@
+from django.conf import settings
 from django.core.exceptions import PermissionDenied
 from django.utils.translation import ugettext as _
 
@@ -29,7 +30,9 @@ class ThreadView(ViewBase):
     def get_posts(self, user, forum, thread, kwargs):
         queryset = self.get_posts_queryset(user, forum, thread)
         queryset = self.exclude_invisible_posts(queryset, user, forum, thread)
-        page = paginate(queryset, kwargs.get('page', 0), 10, 3)
+        page = paginate(queryset, kwargs.get('page', 0),
+                        settings.MISAGO_POSTS_PER_PAGE,
+                        settings.MISAGO_THREAD_TAIL)
 
         posts = []
         for post in page.object_list: