From: Eevee Date: Tue, 7 Sep 2010 03:34:58 +0000 (-0700) Subject: Treat posts as markdown. #262 X-Git-Tag: veekun-promotions/2010091201~1 X-Git-Url: http://git.veekun.com/zzz-spline-forum.git/commitdiff_plain/be07212348141269cd4c5f1544b9a920a6abbfff Treat posts as markdown. #262 --- diff --git a/migration/versions/005_Added_markup_support.py b/migration/versions/005_Added_markup_support.py new file mode 100644 index 0000000..c27c819 --- /dev/null +++ b/migration/versions/005_Added_markup_support.py @@ -0,0 +1,32 @@ +from sqlalchemy import * +from migrate import * +import migrate.changeset + +from sqlalchemy.ext.declarative import declarative_base +TableBase = declarative_base() + +class Post(TableBase): + __tablename__ = 'posts' + id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) + raw_content = Column(Unicode(5120), nullable=False, server_default=u'') + content = Column(Unicode(5120), nullable=False) + + +def upgrade(migrate_engine): + TableBase.metadata.bind = migrate_engine + conn = migrate_engine.connect() + + # Create the column with an empty-string default, copy the old column's + # contents to the new one then remove the default + Post.__table__.c.raw_content.create(connection=conn) + conn.execute( + update(Post.__table__, + values={ Post.__table__.c.raw_content: Post.__table__.c.content }, + ) + ) + Post.__table__.c.raw_content.alter(server_default=None, connection=conn) + +def downgrade(migrate_engine): + TableBase.metadata.bind = migrate_engine + + Post.__table__.c.raw_content.drop() diff --git a/splinext/forum/controllers/forum.py b/splinext/forum/controllers/forum.py index 6cd4bfb..b15302c 100644 --- a/splinext/forum/controllers/forum.py +++ b/splinext/forum/controllers/forum.py @@ -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__) @@ -121,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) diff --git a/splinext/forum/model/__init__.py b/splinext/forum/model/__init__.py index 37beb61..80ca57e 100644 --- a/splinext/forum/model/__init__.py +++ b/splinext/forum/model/__init__.py @@ -73,6 +73,7 @@ class Post(TableBase): position = Column(Integer, nullable=False) author_user_id = Column(Integer, ForeignKey('users.id'), nullable=False) posted_time = Column(DateTime, nullable=False, index=True, default=datetime.now) + raw_content = Column(Unicode(5120), nullable=False) content = Column(Unicode(5120), nullable=False) Index('thread_position', Post.thread_id, Post.position, unique=True) diff --git a/splinext/forum/templates/forum/lib.mako b/splinext/forum/templates/forum/lib.mako index 82884f4..fd2c073 100644 --- a/splinext/forum/templates/forum/lib.mako +++ b/splinext/forum/templates/forum/lib.mako @@ -59,7 +59,7 @@
-
${post.content}
+
${post.content | n}
% endfor