0c8edd316a95b28c14854d62c351ca36ab9b0a03
1 from pkg_resources
import resource_filename
3 from pylons
import c
, session
5 from spline
.lib
.plugin
import PluginBase
6 from spline
.lib
.plugin
import PluginBase
, PluginLink
, Priority
7 from spline
.model
import meta
9 import splinext
.forum
.controllers
.forum
10 from splinext
.forum
import model
as forum_model
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']))
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')
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')
23 class FrontPageNewsPost(object):
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()) \
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
)
44 class ForumPlugin(PluginBase
):
45 def controllers(self
):
47 forum
= splinext
.forum
.controllers
.forum
.ForumController
,
52 ('routes_mapping', Priority
.NORMAL
, add_routes_hook
),
53 ('frontpage_updates', Priority
.NORMAL
, frontpage_hook
),