add versioning to markup languages and reparse old format version posts
This commit is contained in:
@ -2,7 +2,7 @@ from flask import (
|
||||
Blueprint, redirect, url_for, flash, render_template, request
|
||||
)
|
||||
from .users import login_required, get_active_user
|
||||
from ..lib.babycode import babycode_to_html
|
||||
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION
|
||||
from ..constants import InfoboxKind
|
||||
from ..db import db
|
||||
from ..models import Posts, PostHistory, Threads, Topics
|
||||
@ -11,6 +11,7 @@ bp = Blueprint("posts", __name__, url_prefix = "/post")
|
||||
|
||||
|
||||
def create_post(thread_id, user_id, content, markup_language="babycode"):
|
||||
parsed_content = babycode_to_html(content)
|
||||
with db.transaction():
|
||||
post = Posts.create({
|
||||
"thread_id": thread_id,
|
||||
@ -20,10 +21,11 @@ def create_post(thread_id, user_id, content, markup_language="babycode"):
|
||||
|
||||
revision = PostHistory.create({
|
||||
"post_id": post.id,
|
||||
"content": babycode_to_html(content),
|
||||
"content": parsed_content,
|
||||
"is_initial_revision": True,
|
||||
"original_markup": content,
|
||||
"markup_language": markup_language,
|
||||
"format_version": BABYCODE_VERSION,
|
||||
})
|
||||
|
||||
post.update({"current_revision_id": revision.id})
|
||||
@ -31,14 +33,16 @@ def create_post(thread_id, user_id, content, markup_language="babycode"):
|
||||
|
||||
|
||||
def update_post(post_id, new_content, markup_language='babycode'):
|
||||
parsed_content = babycode_to_html(content)
|
||||
with db.transaction():
|
||||
post = Posts.find({'id': post_id})
|
||||
new_revision = PostHistory.create({
|
||||
'post_id': post.id,
|
||||
'content': babycode_to_html(new_content),
|
||||
'content': parsed_content,
|
||||
'is_initial_revision': False,
|
||||
'original_markup': new_content,
|
||||
'markup_language': markup_language,
|
||||
'format_version': BABYCODE_VERSION,
|
||||
})
|
||||
|
||||
post.update({'current_revision_id': new_revision.id})
|
||||
|
Reference in New Issue
Block a user