From dd299c636e8b1bcd77964deed08f71debaf6ae01 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 13 Jan 2023 21:43:14 +0000 Subject: [PATCH] Attachment rather than tag --- posts.py | 2 ++ webapp_post.py | 9 +++++---- webapp_utils.py | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/posts.py b/posts.py index 0ce3847dd..aa4052406 100644 --- a/posts.py +++ b/posts.py @@ -1105,6 +1105,8 @@ def _attach_buy_link(post_json_object: {}, buy_str = 'Buy' if translate.get(buy_str): buy_str = translate[buy_str] + if 'attachment' not in post_json_object: + post_json_object['attachment'] = [] post_json_object['attachment'].append({ "type": "Link", "name": buy_str, diff --git a/webapp_post.py b/webapp_post.py index 98d172b7b..04d243a08 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -2508,10 +2508,11 @@ def individual_post_as_html(signing_priv_key_pem: str, # html for the buy icon buy_str = '' - if post_json_object['object'].get('tag'): - if not is_patch: - buy_links = get_buy_links(post_json_object, translate, buy_sites) - buy_str = _get_buy_footer(buy_links, translate) + if 'attachment' not in post_json_object['object']: + post_json_object['object']['attachment'] = [] + if not is_patch: + buy_links = get_buy_links(post_json_object, translate, buy_sites) + buy_str = _get_buy_footer(buy_links, translate) new_footer_str = \ _get_footer_with_icons(show_icons, diff --git a/webapp_utils.py b/webapp_utils.py index db99b2321..53d635d9b 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -2085,9 +2085,9 @@ def html_following_dropdown(base_dir: str, nickname: str, def get_buy_links(post_json_object: str, translate: {}, buy_sites: {}) -> {}: """Returns any links to buy something from an external site """ - if not post_json_object['object'].get('tag'): + if not post_json_object['object'].get('attachment'): return {} - if not isinstance(post_json_object['object']['tag'], list): + if not isinstance(post_json_object['object']['attachment'], list): return {} links = {} buy_strings = [] @@ -2095,7 +2095,7 @@ def get_buy_links(post_json_object: str, translate: {}, buy_sites: {}) -> {}: if translate.get(buy_str): buy_str = translate[buy_str] buy_strings += buy_str.lower() - for item in post_json_object['object']['tag']: + for item in post_json_object['object']['attachment']: if not isinstance(item, dict): continue if not item.get('name'):