and body text fields to link and image posts

This commit is contained in:
rimu 2024-01-07 18:30:27 +13:00
parent c8f837a52e
commit afa93df35c
6 changed files with 17 additions and 2 deletions

View file

@ -40,8 +40,12 @@ class CreatePostForm(FlaskForm):
discussion_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)}) 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)'}) 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_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://...'}) link_url = StringField(_l('URL'), render_kw={'placeholder': 'https://...'})
image_title = StringField(_l('Title'), validators={Optional(), Length(min=3, max=255)}) 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')) image_file = FileField(_('Image'))
# flair = SelectField(_l('Flair'), coerce=int) # flair = SelectField(_l('Flair'), coerce=int)
nsfw = BooleanField(_l('NSFW')) nsfw = BooleanField(_l('NSFW'))

View file

@ -352,7 +352,7 @@ def add_post(actor):
], ],
'name': post.title, 'name': post.title,
'cc': [], 'cc': [],
'content': post.body_html, 'content': post.body_html if post.body_html else '',
'mediaType': 'text/html', 'mediaType': 'text/html',
'source': { 'source': {
'content': post.body if post.body else '', 'content': post.body if post.body else '',

View file

@ -169,6 +169,8 @@ def save_post(form, post: Post):
post.type = POST_TYPE_ARTICLE post.type = POST_TYPE_ARTICLE
elif form.type.data == 'link': elif form.type.data == 'link':
post.title = form.link_title.data 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 url_changed = post.id is None or form.link_url.data != post.url
post.url = form.link_url.data post.url = form.link_url.data
post.type = POST_TYPE_LINK post.type = POST_TYPE_LINK
@ -204,6 +206,8 @@ def save_post(form, post: Post):
elif form.type.data == 'image': elif form.type.data == 'image':
post.title = form.image_title.data 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 post.type = POST_TYPE_IMAGE
uploaded_file = request.files['image_file'] uploaded_file = request.files['image_file']
if uploaded_file and uploaded_file.filename != '': if uploaded_file and uploaded_file.filename != '':

View file

@ -565,10 +565,12 @@ def post_edit(post_id: int):
elif post.type == constants.POST_TYPE_LINK: elif post.type == constants.POST_TYPE_LINK:
form.type.data = 'link' form.type.data = 'link'
form.link_title.data = post.title form.link_title.data = post.title
form.link_body.data = post.body
form.link_url.data = post.url form.link_url.data = post.url
elif post.type == constants.POST_TYPE_IMAGE: elif post.type == constants.POST_TYPE_IMAGE:
form.type.data = 'image' form.type.data = 'image'
form.image_title.data = post.title form.image_title.data = post.title
form.image_body.data = post.body
form.notify_author.data = post.notify_author form.notify_author.data = post.notify_author
return render_template('post/post_edit.html', title=_('Edit post'), form=form, post=post, return render_template('post/post_edit.html', title=_('Edit post'), form=form, post=post,
images_disabled=images_disabled, markdown_editor=True) images_disabled=images_disabled, markdown_editor=True)

View file

@ -38,12 +38,14 @@
{% endif %} {% endif %}
</div> </div>
<div class="tab-pane fade" id="link-tab-pane" role="tabpanel" aria-labelledby="profile-tab" tabindex="0"> <div class="tab-pane fade" id="link-tab-pane" role="tabpanel" aria-labelledby="profile-tab" tabindex="0">
{{ render_field(form.link_url) }}
{{ render_field(form.link_title) }} {{ render_field(form.link_title) }}
{{ render_field(form.link_url) }}
{{ render_field(form.link_body) }}
</div> </div>
<div class="tab-pane fade" id="image-tab-pane" role="tabpanel" aria-labelledby="contact-tab" tabindex="0"> <div class="tab-pane fade" id="image-tab-pane" role="tabpanel" aria-labelledby="contact-tab" tabindex="0">
{{ render_field(form.image_title) }} {{ render_field(form.image_title) }}
{{ render_field(form.image_file) }} {{ render_field(form.image_file) }}
{{ render_field(form.image_body) }}
</div> </div>
<div class="tab-pane fade" id="poll-tab-pane" role="tabpanel" aria-labelledby="disabled-tab" tabindex="0"> <div class="tab-pane fade" id="poll-tab-pane" role="tabpanel" aria-labelledby="disabled-tab" tabindex="0">
Poll Poll

View file

@ -31,6 +31,9 @@
<a href="{{ post.url }}" rel="nofollow ugc" target="_blank"><img src="{{ post.url }}" style="max-width: 100%; height: auto;" /></a> <a href="{{ post.url }}" rel="nofollow ugc" target="_blank"><img src="{{ post.url }}" style="max-width: 100%; height: auto;" /></a>
{% endif %} {% endif %}
</div> </div>
<div class="post_body mt-2">
{{ post.body_html|safe if post.body_html else '' }}
</div>
</div> </div>
{% else %} {% else %}
<div class="col post_col post_type_normal"> <div class="col post_col post_type_normal">