From afa93df35c37f439d0ad403dff2dbefec601ff94 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 7 Jan 2024 18:30:27 +1300 Subject: [PATCH] and body text fields to link and image posts --- app/community/forms.py | 4 ++++ app/community/routes.py | 2 +- app/community/util.py | 4 ++++ app/post/routes.py | 2 ++ app/templates/community/add_post.html | 4 +++- app/templates/post/_post_full.html | 3 +++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/community/forms.py b/app/community/forms.py index 4b5a5998..eeb43aca 100644 --- a/app/community/forms.py +++ b/app/community/forms.py @@ -40,8 +40,12 @@ class CreatePostForm(FlaskForm): discussion_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)}) discussion_body = TextAreaField(_l('Body'), validators={Optional(), Length(min=3, max=5000)}, render_kw={'placeholder': 'Text (optional)'}) link_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)}) + link_body = TextAreaField(_l('Body'), validators={Optional(), Length(min=3, max=5000)}, + render_kw={'placeholder': 'Text (optional)'}) link_url = StringField(_l('URL'), render_kw={'placeholder': 'https://...'}) image_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)}) + image_body = TextAreaField(_l('Body'), validators={Optional(), Length(min=3, max=5000)}, + render_kw={'placeholder': 'Text (optional)'}) image_file = FileField(_('Image')) # flair = SelectField(_l('Flair'), coerce=int) nsfw = BooleanField(_l('NSFW')) diff --git a/app/community/routes.py b/app/community/routes.py index 680c9c7f..fe34e96c 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -352,7 +352,7 @@ def add_post(actor): ], 'name': post.title, 'cc': [], - 'content': post.body_html, + 'content': post.body_html if post.body_html else '', 'mediaType': 'text/html', 'source': { 'content': post.body if post.body else '', diff --git a/app/community/util.py b/app/community/util.py index 4817f513..42cd7483 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -169,6 +169,8 @@ def save_post(form, post: Post): post.type = POST_TYPE_ARTICLE elif form.type.data == 'link': post.title = form.link_title.data + post.body = form.link_body.data + post.body_html = markdown_to_html(post.body) url_changed = post.id is None or form.link_url.data != post.url post.url = form.link_url.data post.type = POST_TYPE_LINK @@ -204,6 +206,8 @@ def save_post(form, post: Post): elif form.type.data == 'image': post.title = form.image_title.data + post.body = form.image_body.data + post.body_html = markdown_to_html(post.body) post.type = POST_TYPE_IMAGE uploaded_file = request.files['image_file'] if uploaded_file and uploaded_file.filename != '': diff --git a/app/post/routes.py b/app/post/routes.py index 30520db5..19f02a6c 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -565,10 +565,12 @@ def post_edit(post_id: int): elif post.type == constants.POST_TYPE_LINK: form.type.data = 'link' form.link_title.data = post.title + form.link_body.data = post.body form.link_url.data = post.url elif post.type == constants.POST_TYPE_IMAGE: form.type.data = 'image' form.image_title.data = post.title + form.image_body.data = post.body form.notify_author.data = post.notify_author return render_template('post/post_edit.html', title=_('Edit post'), form=form, post=post, images_disabled=images_disabled, markdown_editor=True) diff --git a/app/templates/community/add_post.html b/app/templates/community/add_post.html index 3f4a7705..46a983f0 100644 --- a/app/templates/community/add_post.html +++ b/app/templates/community/add_post.html @@ -38,12 +38,14 @@ {% endif %}
{{ render_field(form.image_title) }} {{ render_field(form.image_file) }} + {{ render_field(form.image_body) }}
Poll diff --git a/app/templates/post/_post_full.html b/app/templates/post/_post_full.html index be6315af..8f407c4b 100644 --- a/app/templates/post/_post_full.html +++ b/app/templates/post/_post_full.html @@ -31,6 +31,9 @@ {% endif %}
+
+ {{ post.body_html|safe if post.body_html else '' }} +
{% else %}