Handle non-compliant wordpress contentMap

merge-requests/30/head
Bob Mottram 2023-10-12 17:11:37 +01:00
parent 03735ea75d
commit 8b22e91b11
1 changed files with 25 additions and 23 deletions

View File

@ -249,31 +249,33 @@ def get_content_from_post(post_json_object: {}, system_language: str,
if has_object_dict(post_json_object): if has_object_dict(post_json_object):
this_post_json = post_json_object['object'] this_post_json = post_json_object['object']
map_dict = content_type + 'Map' map_dict = content_type + 'Map'
if not this_post_json.get(content_type) and \ has_contentmap_dict = False
not this_post_json.get(map_dict):
return ''
content = ''
map_dict = content_type + 'Map'
if this_post_json.get(map_dict): if this_post_json.get(map_dict):
if isinstance(this_post_json[map_dict], dict): if isinstance(this_post_json[map_dict], dict):
if this_post_json[map_dict].get(system_language): has_contentmap_dict = True
sys_lang = this_post_json[map_dict][system_language] if not this_post_json.get(content_type) and \
if isinstance(sys_lang, str): not has_contentmap_dict:
content = sys_lang return ''
content = remove_markup_tag(content, 'pre') content = ''
content = content.replace('&', '&') if has_contentmap_dict:
return standardize_text(content) if this_post_json[map_dict].get(system_language):
else: sys_lang = this_post_json[map_dict][system_language]
# is there a contentMap/summaryMap entry for one of if isinstance(sys_lang, str):
# the understood languages? content = sys_lang
for lang in languages_understood: content = remove_markup_tag(content, 'pre')
if this_post_json[map_dict].get(lang): content = content.replace('&', '&')
map_lang = this_post_json[map_dict][lang] return standardize_text(content)
if isinstance(map_lang, str): else:
content = map_lang # is there a contentMap/summaryMap entry for one of
content = remove_markup_tag(content, 'pre') # the understood languages?
content = content.replace('&', '&') for lang in languages_understood:
return standardize_text(content) if this_post_json[map_dict].get(lang):
map_lang = this_post_json[map_dict][lang]
if isinstance(map_lang, str):
content = map_lang
content = remove_markup_tag(content, 'pre')
content = content.replace('&', '&')
return standardize_text(content)
else: else:
if isinstance(this_post_json[content_type], str): if isinstance(this_post_json[content_type], str):
content = this_post_json[content_type] content = this_post_json[content_type]