93eaed44412bfc4e5066d304d69460e80917ed5a
[zzz-spline-forum.git] / splinext / forum / controllers / forum.py
1 import logging
2
3 from pylons import config, request, response, session, tmpl_context as c, url
4 from pylons.controllers.util import abort, redirect_to
5 from routes import request_config
6 from sqlalchemy.orm.exc import NoResultFound
7
8 from spline.model import meta
9 from spline.lib import helpers as h
10 from spline.lib.base import BaseController, render
11 from splinext.forum import model as forum_model
12
13 log = logging.getLogger(__name__)
14
15 class ForumController(BaseController):
16
17 def forums(self):
18 c.forums = meta.Session.query(forum_model.Forum) \
19 .order_by(forum_model.Forum.id.asc())
20 return render('/forum/forums.mako')
21
22 def threads(self, forum_id):
23 try:
24 c.forum = meta.Session.query(forum_model.Forum).get(forum_id)
25 except NoResultFound:
26 abort(404)
27
28 c.threads = c.forum.threads
29
30 return render('/forum/threads.mako')
31
32 def posts(self, forum_id, thread_id):
33 try:
34 c.thread = meta.Session.query(forum_model.Thread) \
35 .filter_by(id=thread_id, forum_id=forum_id).one()
36 except NoResultFound:
37 abort(404)
38
39 return render('/forum/posts.mako')