add rss content to post history and generate it when creating or editing a post

This commit is contained in:
2025-12-14 07:05:52 +03:00
parent 96c37f9081
commit 0898c56a51
2 changed files with 6 additions and 1 deletions

View File

@@ -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, BABYCODE_VERSION
from ..lib.babycode import babycode_to_html, babycode_to_rssxml, BABYCODE_VERSION
from ..constants import InfoboxKind
from ..db import db
from ..models import Posts, PostHistory, Threads, Topics, Mentions
@@ -12,6 +12,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)
parsed_rss = babycode_to_rssxml(content)
with db.transaction():
post = Posts.create({
"thread_id": thread_id,
@@ -22,6 +23,7 @@ def create_post(thread_id, user_id, content, markup_language="babycode"):
revision = PostHistory.create({
"post_id": post.id,
"content": parsed_content.result,
"content_rss": parsed_rss,
"is_initial_revision": True,
"original_markup": content,
"markup_language": markup_language,
@@ -43,11 +45,13 @@ 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(new_content)
parsed_rss = babycode_to_rssxml(new_content)
with db.transaction():
post = Posts.find({'id': post_id})
new_revision = PostHistory.create({
'post_id': post.id,
'content': parsed_content.result,
"content_rss": parsed_rss,
'is_initial_revision': False,
'original_markup': new_content,
'markup_language': markup_language,