Show recent forum threads on the front page. Sucks, but.
[zzz-spline-forum.git] / splinext / forum / __init__.py
1 from pkg_resources import resource_filename
2
3 from pylons import session, tmpl_context as c
4 from routes import url_for as url
5
6 from spline.lib.plugin import PluginBase
7 from spline.lib.plugin import PluginBase, PluginLink, Priority
8
9 import splinext.forum.controllers.forum
10
11 def add_routes_hook(map, *args, **kwargs):
12 """Hook to inject some of our behavior into the routes configuration."""
13 require_GET = dict(conditions=dict(method=['GET']))
14 require_POST = dict(conditions=dict(method=['POST']))
15
16 map.connect('/forums', controller='forum', action='forums')
17 map.connect(r'/forums/{forum_id:\d+}', controller='forum', action='threads')
18 map.connect(r'/forums/{forum_id:\d+}/threads/{thread_id:\d+}', controller='forum', action='posts')
19
20 map.connect(r'/forums/{forum_id:\d+}/write', controller='forum', action='write_thread', **require_GET)
21 map.connect(r'/forums/{forum_id:\d+}/write', controller='forum', action='write_thread_commit', **require_POST)
22 map.connect(r'/forums/{forum_id:\d+}/threads/{thread_id:\d+}/write', controller='forum', action='write', **require_GET)
23 map.connect(r'/forums/{forum_id:\d+}/threads/{thread_id:\d+}/write', controller='forum', action='write_commit', **require_POST)
24
25
26 class ForumPlugin(PluginBase):
27 def controllers(self):
28 return dict(
29 forum = splinext.forum.controllers.forum.ForumController,
30 )
31
32 def links(self):
33 return [
34 PluginLink(u'Forums', url(controller='forum', action='forums')),
35 ]
36
37 def hooks(self):
38 hooks = [
39 ('routes_mapping', Priority.NORMAL, add_routes_hook),
40 ]
41
42 # frontpage plugin may or may not be installed
43 try:
44 from splinext.forum.frontpage_sources import ForumSource, forum_activity
45 hooks.append(
46 ('frontpage_updates_forum', Priority.NORMAL, ForumSource))
47 hooks.append(
48 ('frontpage_extras', Priority.NORMAL, forum_activity))
49 except ImportError:
50 pass
51
52 return hooks