0c8edd316a95b28c14854d62c351ca36ab9b0a03
[zzz-spline-forum.git] / splinext / forum / __init__.py
1 from pkg_resources import resource_filename
2
3 from pylons import c, session
4
5 from spline.lib.plugin import PluginBase
6 from spline.lib.plugin import PluginBase, PluginLink, Priority
7 from spline.model import meta
8
9 import splinext.forum.controllers.forum
10 from splinext.forum import model as forum_model
11
12 def add_routes_hook(map, *args, **kwargs):
13 """Hook to inject some of our behavior into the routes configuration."""
14 require_POST = dict(conditions=dict(method=['POST']))
15
16 map.connect('/forums', controller='forum', action='forums')
17 map.connect('/forums/{forum_id}', controller='forum', action='threads')
18 map.connect('/forums/{forum_id}/threads/{thread_id}', controller='forum', action='posts')
19
20 map.connect('/forums/{forum_id}/write', controller='forum', action='write_thread')
21 map.connect('/forums/{forum_id}/threads/{thread_id}/write', controller='forum', action='write')
22
23 class FrontPageNewsPost(object):
24 pass
25
26 def frontpage_hook(limit):
27 """Hook to return recent news for the front page."""
28 threads = meta.Session.query(forum_model.Thread) \
29 .join(forum_model.Thread.first_post) \
30 .order_by(forum_model.Post.posted_time.desc()) \
31 [:limit]
32
33 updates = []
34 for thread in threads:
35 update = FrontPageNewsPost()
36 update.time = thread.first_post.posted_time
37 update.template = '/forum/front_page.mako'
38 update.post = thread.first_post
39 updates.append(update)
40
41 return updates
42
43
44 class ForumPlugin(PluginBase):
45 def controllers(self):
46 return dict(
47 forum = splinext.forum.controllers.forum.ForumController,
48 )
49
50 def hooks(self):
51 return [
52 ('routes_mapping', Priority.NORMAL, add_routes_hook),
53 ('frontpage_updates', Priority.NORMAL, frontpage_hook),
54 ]