Update to new frontpage API, and keep frontpage optional.
[zzz-spline-forum.git] / splinext / forum / __init__.py
index 0c8edd3..07db391 100644 (file)
@@ -4,10 +4,8 @@ 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."""
@@ -20,26 +18,6 @@ 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):
@@ -48,7 +26,16 @@ class ForumPlugin(PluginBase):
         )
 
     def hooks(self):
-        return [
+        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
+            hooks.append(
+                ('frontpage_updates_forum', Priority.NORMAL, ForumSource))
+        except ImportError:
+            pass
+
+        return hooks