Added front page support.
authorEevee <git@veekun.com>
Thu, 15 Jul 2010 05:59:35 +0000 (22:59 -0700)
committerEevee <git@veekun.com>
Thu, 15 Jul 2010 05:59:35 +0000 (22:59 -0700)
splinext/forum/__init__.py
splinext/forum/templates/forum/front_page.mako [new file with mode: 0644]

index e234c14..0c8edd3 100644 (file)
@@ -4,8 +4,10 @@ from pylons import c, session
 
 from spline.lib.plugin import PluginBase
 from spline.lib.plugin import PluginBase, PluginLink, Priority
+from spline.model import meta
 
 import splinext.forum.controllers.forum
+from splinext.forum import model as forum_model
 
 def add_routes_hook(map, *args, **kwargs):
     """Hook to inject some of our behavior into the routes configuration."""
@@ -18,6 +20,26 @@ def add_routes_hook(map, *args, **kwargs):
     map.connect('/forums/{forum_id}/write', controller='forum', action='write_thread')
     map.connect('/forums/{forum_id}/threads/{thread_id}/write', controller='forum', action='write')
 
+class FrontPageNewsPost(object):
+    pass
+
+def frontpage_hook(limit):
+    """Hook to return recent news for the front page."""
+    threads = meta.Session.query(forum_model.Thread) \
+        .join(forum_model.Thread.first_post) \
+        .order_by(forum_model.Post.posted_time.desc()) \
+        [:limit]
+
+    updates = []
+    for thread in threads:
+        update = FrontPageNewsPost()
+        update.time = thread.first_post.posted_time
+        update.template = '/forum/front_page.mako'
+        update.post = thread.first_post
+        updates.append(update)
+
+    return updates
+
 
 class ForumPlugin(PluginBase):
     def controllers(self):
@@ -28,4 +50,5 @@ class ForumPlugin(PluginBase):
     def hooks(self):
         return [
             ('routes_mapping',    Priority.NORMAL,      add_routes_hook),
+            ('frontpage_updates', Priority.NORMAL,      frontpage_hook),
         ]
diff --git a/splinext/forum/templates/forum/front_page.mako b/splinext/forum/templates/forum/front_page.mako
new file mode 100644 (file)
index 0000000..b967763
--- /dev/null
@@ -0,0 +1,25 @@
+<%page args="update" />
+<%namespace name="userlib" file="/users/lib.mako" />
+
+<div class="frontpage-update">
+    <div class="header">
+        <div class="category"><img src="${h.static_uri('spline', 'icons/newspapers.png')}" alt=""> ${config['spline.site_title']} news:</div>
+        <div class="title">
+            <a href="${url(controller='forum', action='posts', forum_id=update.post.thread.forum.id, thread_id=update.post.thread.id)}">
+                ${update.post.thread.subject}
+            </a>
+        </div>
+        <div class="date">${update.post.posted_time}</div>
+    </div>
+    <div class="avatar">
+        <a href="${url(controller='users', action='profile', id=update.post.author.id, name=update.post.author.name)}">
+            ${userlib.avatar(update.post.author, size=48)}
+        </a>
+    </div>
+    <div class="content">${update.post.content}</div>
+    <div class="comments">
+        <a href="${url(controller='forum', action='posts', forum_id=update.post.thread.forum.id, thread_id=update.post.thread.id)}">
+            ${update.post.thread.post_count - 1} comment${'' if update.post.thread.post_count == 2 else 's'}
+        </a>
+    </div>
+</div>