edit post with hashtags

This commit is contained in:
rimu 2024-10-30 09:19:32 +13:00
parent b635dc5ee8
commit ea4df1d2f0

View file

@ -426,7 +426,7 @@ def save_post(form, post: Post, type: int):
db.session.add(post) db.session.add(post)
else: else:
db.session.execute(text('DELETE FROM "post_tag" WHERE post_id = :post_id'), {'post_id': post.id}) db.session.execute(text('DELETE FROM "post_tag" WHERE post_id = :post_id'), {'post_id': post.id})
post.tags = tags_from_string(form.tags.data) post.tags = tags_from_string_old(form.tags.data)
db.session.commit() db.session.commit()
# Save poll choices. NB this will delete all votes whenever a poll is edited. Partially because it's easier to code but also to stop malicious alterations to polls after people have already voted # Save poll choices. NB this will delete all votes whenever a poll is edited. Partially because it's easier to code but also to stop malicious alterations to polls after people have already voted
@ -500,6 +500,22 @@ def tags_from_string(tags: str) -> List[dict]:
return return_value return return_value
def tags_from_string_old(tags: str) -> List[Tag]:
return_value = []
tags = tags.strip()
if tags == '':
return []
tag_list = tags.split(',')
tag_list = [tag.strip() for tag in tag_list]
for tag in tag_list:
if tag[0] == '#':
tag = tag[1:]
tag_to_append = find_hashtag_or_create(tag)
if tag_to_append:
return_value.append(tag_to_append)
return return_value
def delete_post_from_community(post_id): def delete_post_from_community(post_id):
if current_app.debug: if current_app.debug:
delete_post_from_community_task(post_id) delete_post_from_community_task(post_id)