creating threads
This commit is contained in:
26
app/routes/posts.py
Normal file
26
app/routes/posts.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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
|
||||
|
Reference in New Issue
Block a user