Show recent forum threads on the front page. Sucks, but.
[zzz-spline-forum.git] / splinext / forum / __init__.py
index 0c8edd3..5794a4c 100644 (file)
@@ -1,44 +1,26 @@
 from pkg_resources import resource_filename
 
-from pylons import c, session
+from pylons import session, tmpl_context as c
+from routes import url_for as url
 
 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."""
+    require_GET = dict(conditions=dict(method=['GET']))
     require_POST = dict(conditions=dict(method=['POST']))
 
     map.connect('/forums', controller='forum', action='forums')
-    map.connect('/forums/{forum_id}', controller='forum', action='threads')
-    map.connect('/forums/{forum_id}/threads/{thread_id}', controller='forum', action='posts')
+    map.connect(r'/forums/{forum_id:\d+}', controller='forum', action='threads')
+    map.connect(r'/forums/{forum_id:\d+}/threads/{thread_id:\d+}', controller='forum', action='posts')
 
-    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
+    map.connect(r'/forums/{forum_id:\d+}/write', controller='forum', action='write_thread', **require_GET)
+    map.connect(r'/forums/{forum_id:\d+}/write', controller='forum', action='write_thread_commit', **require_POST)
+    map.connect(r'/forums/{forum_id:\d+}/threads/{thread_id:\d+}/write', controller='forum', action='write', **require_GET)
+    map.connect(r'/forums/{forum_id:\d+}/threads/{thread_id:\d+}/write', controller='forum', action='write_commit', **require_POST)
 
 
 class ForumPlugin(PluginBase):
@@ -47,8 +29,24 @@ class ForumPlugin(PluginBase):
             forum = splinext.forum.controllers.forum.ForumController,
         )
 
-    def hooks(self):
+    def links(self):
         return [
+            PluginLink(u'Forums', url(controller='forum', action='forums')),
+        ]
+
+    def hooks(self):
+        hooks = [
             ('routes_mapping',    Priority.NORMAL,      add_routes_hook),
-            ('frontpage_updates', Priority.NORMAL,      frontpage_hook),
         ]
+
+        # frontpage plugin may or may not be installed
+        try:
+            from splinext.forum.frontpage_sources import ForumSource, forum_activity
+            hooks.append(
+                ('frontpage_updates_forum', Priority.NORMAL, ForumSource))
+            hooks.append(
+                ('frontpage_extras', Priority.NORMAL, forum_activity))
+        except ImportError:
+            pass
+
+        return hooks