add subscribing and unsubscribing, add post editing
This commit is contained in:
@@ -102,6 +102,9 @@ class Users(Model):
|
||||
def get_badges(self):
|
||||
return Badges.findall({'user_id': int(self.id)})
|
||||
|
||||
def is_subscribed(self, thread_id):
|
||||
return Subscriptions.count({'user_id': self.id, 'thread_id': thread_id}) > 0
|
||||
|
||||
|
||||
class Topics(Model):
|
||||
table = 'topics'
|
||||
@@ -327,7 +330,8 @@ class Posts(Model):
|
||||
for mention in html_content.mentions:
|
||||
Mentions.create({
|
||||
'revision_id': revision.id,
|
||||
'mentioned_iser_id': mention['mentioned_iser_id'],
|
||||
'mentioned_user_id': mention['mentioned_user_id'],
|
||||
'original_mention_text': mention['mention_text'],
|
||||
'start_index': mention['start'],
|
||||
'end_index': mention['end'],
|
||||
})
|
||||
@@ -335,6 +339,32 @@ class Posts(Model):
|
||||
post.update({'current_revision_id': revision.id})
|
||||
return post
|
||||
|
||||
def edit(self, new_content: str, language: str = 'babycode'):
|
||||
from .lib.babycode import babycode_to_html, babycode_to_rssxml, BABYCODE_VERSION
|
||||
html_content = babycode_to_html(new_content)
|
||||
rssxml_content = babycode_to_rssxml(new_content)
|
||||
with db.transaction():
|
||||
revision = PostHistory.create({
|
||||
'post_id': self.id,
|
||||
'content': html_content.result,
|
||||
'content_rss': rssxml_content,
|
||||
'is_initial_revision': False,
|
||||
'original_markup': new_content,
|
||||
'markup_language': language,
|
||||
'format_version': BABYCODE_VERSION,
|
||||
})
|
||||
|
||||
for mention in html_content.mentions:
|
||||
Mentions.create({
|
||||
'revision_id': revision.id,
|
||||
'mentioned_user_id': mention['mentioned_user_id'],
|
||||
'original_mention_text': mention['mention_text'],
|
||||
'start_index': mention['start'],
|
||||
'end_index': mention['end'],
|
||||
})
|
||||
|
||||
self.update({'current_revision_id': revision.id})
|
||||
|
||||
class PostHistory(Model):
|
||||
table = 'post_history'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user