27 lines
804 B
Python
27 lines
804 B
Python
from flask import Blueprint, redirect, url_for
|
|
from ..lib.babycode import babycode_to_html
|
|
from ..db import db
|
|
from ..models import Posts, PostHistory
|
|
|
|
bp = Blueprint("posts", __name__, url_prefix = "/posts")
|
|
|
|
def create_post(thread_id, user_id, content, markup_language="babycode"):
|
|
with db.transaction():
|
|
post = Posts.create({
|
|
"thread_id": thread_id,
|
|
"user_id": user_id,
|
|
"current_revision_id": None,
|
|
})
|
|
|
|
revision = PostHistory.create({
|
|
"post_id": post.id,
|
|
"content": babycode_to_html(content),
|
|
"is_initial_revision": True,
|
|
"original_markup": content,
|
|
"markup_language": markup_language,
|
|
})
|
|
|
|
post.update({"current_revision_id": revision.id})
|
|
return post
|
|
|