X-Git-Url: http://git.veekun.com/zzz-spline-forum.git/blobdiff_plain/dfc83133694768eb466d4a55bbb2c501ac508e92..be07212348141269cd4c5f1544b9a920a6abbfff:/splinext/forum/controllers/forum.py diff --git a/splinext/forum/controllers/forum.py b/splinext/forum/controllers/forum.py index b5bacab..b15302c 100644 --- a/splinext/forum/controllers/forum.py +++ b/splinext/forum/controllers/forum.py @@ -1,7 +1,7 @@ import logging from pylons import config, request, response, session, tmpl_context as c, url -from pylons.controllers.util import abort, redirect_to +from pylons.controllers.util import abort, redirect from routes import request_config from sqlalchemy.orm.exc import NoResultFound import wtforms @@ -10,6 +10,7 @@ from wtforms import fields from spline.model import meta from spline.lib import helpers as h from spline.lib.base import BaseController, render +import spline.lib.markdown from splinext.forum import model as forum_model log = logging.getLogger(__name__) @@ -29,9 +30,8 @@ class ForumController(BaseController): return render('/forum/forums.mako') def threads(self, forum_id): - try: - c.forum = meta.Session.query(forum_model.Forum).get(forum_id) - except NoResultFound: + c.forum = meta.Session.query(forum_model.Forum).get(forum_id) + if not c.forum: abort(404) c.write_thread_form = WriteThreadForm() @@ -54,7 +54,7 @@ class ForumController(BaseController): def write_thread(self, forum_id): """Provides a form for posting a new thread.""" - if not c.user.can('create_forum_thread'): + if not c.user.can('forum:create-thread'): abort(403) try: @@ -93,13 +93,15 @@ class ForumController(BaseController): # Redirect to the new thread h.flash("Contribution to the collective knowledge of the species successfully recorded.") - redirect_to(controller='forum', action='posts', - forum_id=forum_id, thread_id=thread.id, - _code=303) + redirect( + url(controller='forum', action='posts', + forum_id=forum_id, thread_id=thread.id), + code=303, + ) def write(self, forum_id, thread_id): """Provides a form for posting to a thread.""" - if not c.user.can('create_forum_post'): + if not c.user.can('forum:create-post'): abort(403) try: @@ -120,10 +122,12 @@ class ForumController(BaseController): .with_lockmode('update') \ .get(c.thread.id) + source = c.write_post_form.content.data post = forum_model.Post( position = c.thread.post_count + 1, author_user_id = c.user.id, - content = c.write_post_form.content.data, + raw_content = source, + content = spline.lib.markdown.translate(source), ) c.thread.posts.append(post) @@ -134,6 +138,8 @@ class ForumController(BaseController): # Redirect to the thread # XXX probably to the post instead; anchor? depends on paging scheme h.flash('Your uniqueness has been added to our own.') - redirect_to(controller='forum', action='posts', - forum_id=forum_id, thread_id=thread_id, - _code=303) + redirect( + url(controller='forum', action='posts', + forum_id=forum_id, thread_id=thread_id), + code=303, + )