From eda83e616ace71957edf96a49a6e80ea3ae27b2a Mon Sep 17 00:00:00 2001 From: Eevee Date: Wed, 15 Sep 2010 00:19:21 -0700 Subject: [PATCH] Paging for threads and posts! #314 --- splinext/forum/controllers/forum.py | 27 +++++++++++++++++++++++---- splinext/forum/templates/css/forum.mako | 1 + splinext/forum/templates/forum/lib.mako | 1 + splinext/forum/templates/forum/posts.mako | 5 ++++- splinext/forum/templates/forum/threads.mako | 3 +++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/splinext/forum/controllers/forum.py b/splinext/forum/controllers/forum.py index 5d962e0..0d1207f 100644 --- a/splinext/forum/controllers/forum.py +++ b/splinext/forum/controllers/forum.py @@ -147,10 +147,18 @@ class ForumController(BaseController): c.write_thread_form = WriteThreadForm() - c.threads = c.forum.threads.options( - joinedload('last_post'), - joinedload('last_post.author'), - ) + # nb: This will never show post-less threads. Oh well! + threads_q = c.forum.threads \ + .join(forum_model.Thread.last_post) \ + .order_by(forum_model.Post.posted_time.desc()) \ + .options(joinedload('last_post.author')) + c.num_threads = threads_q.count() + try: + c.skip = int(request.params.get('skip', 0)) + except ValueError: + abort(404) + c.per_page = 89 + c.threads = threads_q.offset(c.skip).limit(c.per_page) return render('/forum/threads.mako') @@ -163,6 +171,17 @@ class ForumController(BaseController): c.write_post_form = WritePostForm() + posts_q = c.thread.posts \ + .order_by(forum_model.Post.position.asc()) \ + .options(joinedload('author')) + c.num_posts = c.thread.post_count + try: + c.skip = int(request.params.get('skip', 0)) + except ValueError: + abort(404) + c.per_page = 89 + c.posts = posts_q.offset(c.skip).limit(c.per_page) + return render('/forum/posts.mako') diff --git a/splinext/forum/templates/css/forum.mako b/splinext/forum/templates/css/forum.mako index 8ba2b01..e36cb40 100644 --- a/splinext/forum/templates/css/forum.mako +++ b/splinext/forum/templates/css/forum.mako @@ -28,5 +28,6 @@ table.forum-list td.stats.whoanelly { font-weight: bold; color: #6855aa; } .forum-post .author .avatar { margin-bottom: 1em; } .forum-post .author .avatar img { -moz-box-shadow: 0 0 2px black; } .forum-post .meta { padding: 0.5em 1em; border: 1px solid #b4c7e6; background: url(${h.static_uri('local', 'images/layout/th-background.png')}) left bottom repeat-x; -moz-border-radius-topleft: 0.5em; -moz-border-radius-topright: 0.5em; -webkit-border-top-left-radius: 0.5em; -webkit-border-top-right-radius: 0.5em; } +.forum-post .meta a { display: block; float: right; } .forum-post .content { min-height: 12em; margin-right: 18.5em; padding: 1em; } .forum-post:nth-child(2n) { background: #f4f4f4; } diff --git a/splinext/forum/templates/forum/lib.mako b/splinext/forum/templates/forum/lib.mako index fd2c073..c82a8b2 100644 --- a/splinext/forum/templates/forum/lib.mako +++ b/splinext/forum/templates/forum/lib.mako @@ -57,6 +57,7 @@
+ #${post.position}
${post.content | n}
diff --git a/splinext/forum/templates/forum/posts.mako b/splinext/forum/templates/forum/posts.mako index 773fd9c..fed55a1 100644 --- a/splinext/forum/templates/forum/posts.mako +++ b/splinext/forum/templates/forum/posts.mako @@ -1,5 +1,6 @@ <%inherit file="/base.mako" /> <%namespace name="forumlib" file="/forum/lib.mako" /> +<%namespace name="lib" file="/lib.mako" /> <%def name="title()">${c.thread.subject} - Forums @@ -17,7 +18,9 @@ ${forumlib.hierarchy(c.thread.forum, c.thread)} % if c.thread.post_count == 0:

Something terribly bogus has happened; this thread has no posts.

% else: -${forumlib.posts(c.thread.posts)} +${lib.pager(c.skip, c.per_page, c.thread.post_count, dict(controller='forum', action='posts', forum_id=c.thread.forum_id, thread_id=c.thread.id))} +${forumlib.posts(c.posts)} +${lib.pager(c.skip, c.per_page, c.thread.post_count, dict(controller='forum', action='posts', forum_id=c.thread.forum_id, thread_id=c.thread.id))} % endif ${forumlib.write_post_form(c.thread)} diff --git a/splinext/forum/templates/forum/threads.mako b/splinext/forum/templates/forum/threads.mako index cf510e7..d55914a 100644 --- a/splinext/forum/templates/forum/threads.mako +++ b/splinext/forum/templates/forum/threads.mako @@ -1,6 +1,7 @@ <%inherit file="/base.mako" /> <%namespace name="forumlib" file="/forum/lib.mako" /> <%namespace name="userlib" file="/users/lib.mako" /> +<%namespace name="lib" file="/lib.mako" /> <%def name="title()">${c.forum.name} - Forums @@ -14,6 +15,7 @@

Threads

${forumlib.hierarchy(c.forum)} +${lib.pager(c.skip, c.per_page, c.num_threads, dict(controller='forum', action='threads', forum_id=c.forum.id))} @@ -43,5 +45,6 @@ ${forumlib.hierarchy(c.forum)} % endfor
+${lib.pager(c.skip, c.per_page, c.num_threads, dict(controller='forum', action='threads', forum_id=c.forum.id))} ${forumlib.write_thread_form(c.forum)} -- 2.7.4