Paging for threads and posts! #314 veekun-promotions/2010091501 veekun-promotions/2010091901 veekun-promotions/2010091902
authorEevee <git@veekun.com>
Wed, 15 Sep 2010 07:19:21 +0000 (00:19 -0700)
committerEevee <git@veekun.com>
Wed, 15 Sep 2010 07:19:21 +0000 (00:19 -0700)
splinext/forum/controllers/forum.py
splinext/forum/templates/css/forum.mako
splinext/forum/templates/forum/lib.mako
splinext/forum/templates/forum/posts.mako
splinext/forum/templates/forum/threads.mako

index 5d962e0..0d1207f 100644 (file)
@@ -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')
 
 
index 8ba2b01..e36cb40 100644 (file)
@@ -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; }
index fd2c073..c82a8b2 100644 (file)
@@ -57,6 +57,7 @@
             </div>
         </div>
         <div class="meta">
+            <a href="${url(controller='forum', action='posts', forum_id=post.thread.forum_id, thread_id=post.thread.id)}">#${post.position}</a>
             <time>${post.posted_time}</time>
         </div>
         <div class="content">${post.content | n}</div>
index 773fd9c..fed55a1 100644 (file)
@@ -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</%def>
 
@@ -17,7 +18,9 @@ ${forumlib.hierarchy(c.thread.forum, c.thread)}
 % if c.thread.post_count == 0:
 <p>Something terribly bogus has happened; this thread has no posts.</p>
 % 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)}
index cf510e7..d55914a 100644 (file)
@@ -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</%def>
 
@@ -14,6 +15,7 @@
 <h1>Threads</h1>
 ${forumlib.hierarchy(c.forum)}
 
+${lib.pager(c.skip, c.per_page, c.num_threads, dict(controller='forum', action='threads', forum_id=c.forum.id))}
 <table class="forum-list striped-rows">
 <thead>
     <tr class="header-row">
@@ -43,5 +45,6 @@ ${forumlib.hierarchy(c.forum)}
     % endfor
 </tbody>
 </table>
+${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)}