--- /dev/null
+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()
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__)
.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)
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)
<div class="meta">
<time>${post.posted_time}</time>
</div>
- <div class="content">${post.content}</div>
+ <div class="content">${post.content | n}</div>
</div>
% endfor
</div>