mirror of https://gitlab.com/bashrc2/epicyon
Use function to obtain content
parent
b12932e075
commit
d32b49e4e2
31
content.py
31
content.py
|
@ -15,6 +15,7 @@ import email.parser
|
|||
import urllib.parse
|
||||
from shutil import copyfile
|
||||
from dateutil.parser import parse
|
||||
from utils import get_content_from_post
|
||||
from utils import get_full_domain
|
||||
from utils import get_user_paths
|
||||
from utils import convert_published_to_local_timezone
|
||||
|
@ -2000,7 +2001,8 @@ def content_diff(content: str, prev_content: str) -> str:
|
|||
|
||||
def create_edits_html(edits_json: {}, post_json_object: {},
|
||||
translate: {}, timezone: str,
|
||||
system_language: str) -> str:
|
||||
system_language: str,
|
||||
languages_understood: []) -> str:
|
||||
""" Creates html showing historical edits made to a post
|
||||
"""
|
||||
if not edits_json:
|
||||
|
@ -2015,33 +2017,18 @@ def create_edits_html(edits_json: {}, post_json_object: {},
|
|||
edit_dates_list.append(modified)
|
||||
edit_dates_list.sort(reverse=True)
|
||||
edits_str = ''
|
||||
content = None
|
||||
if 'contentMap' in post_json_object['object']:
|
||||
if post_json_object['object']['contentMap'].get(system_language):
|
||||
content = \
|
||||
post_json_object['object']['contentMap'][system_language]
|
||||
if content is None:
|
||||
if 'content' in post_json_object['object']:
|
||||
content = post_json_object['object']['content']
|
||||
if content is None:
|
||||
content = get_content_from_post(post_json_object, system_language,
|
||||
languages_understood)
|
||||
if not content:
|
||||
return ''
|
||||
content = remove_html(content)
|
||||
for modified in edit_dates_list:
|
||||
prev_json = edits_json[modified]
|
||||
if not has_object_dict(prev_json):
|
||||
continue
|
||||
prev_content = None
|
||||
if 'content' not in prev_json['object']:
|
||||
if 'contentMap' not in prev_json['object']:
|
||||
continue
|
||||
if 'contentMap' in prev_json['object']:
|
||||
if prev_json['object']['contentMap'].get(system_language):
|
||||
prev_content = \
|
||||
prev_json['object']['contentMap'][system_language]
|
||||
if prev_content is None:
|
||||
if 'content' in prev_json['object']:
|
||||
prev_content = prev_json['object']['content']
|
||||
if prev_content is None:
|
||||
prev_content = get_content_from_post(prev_json, system_language,
|
||||
languages_understood)
|
||||
if not prev_content:
|
||||
continue
|
||||
prev_content = remove_html(prev_content)
|
||||
if content == prev_content:
|
||||
|
|
3
tests.py
3
tests.py
|
@ -7446,6 +7446,7 @@ def _test_diff_content() -> None:
|
|||
assert result == expected
|
||||
|
||||
system_language = "en"
|
||||
languages_understood = ["en"]
|
||||
translate = {
|
||||
"SHOW EDITS": "SHOW EDITS"
|
||||
}
|
||||
|
@ -7483,7 +7484,7 @@ def _test_diff_content() -> None:
|
|||
}
|
||||
html_str = \
|
||||
create_edits_html(edits_json, post_json_object, translate,
|
||||
timezone, system_language)
|
||||
timezone, system_language, languages_understood)
|
||||
assert html_str
|
||||
expected = \
|
||||
'<details><summary class="cw" tabindex="10">SHOW EDITS</summary>' + \
|
||||
|
|
|
@ -1961,13 +1961,6 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
edits_post_url = \
|
||||
remove_id_ending(message_id.strip()).replace('/', '#') + '.edits'
|
||||
account_dir = acct_dir(base_dir, nickname, domain) + '/'
|
||||
edits_filename = account_dir + box_name + '/' + edits_post_url
|
||||
edits_str = ''
|
||||
if os.path.isfile(edits_filename):
|
||||
edits_json = load_json(edits_filename, 0, 1)
|
||||
if edits_json:
|
||||
edits_str = create_edits_html(edits_json, post_json_object,
|
||||
translate, timezone, system_language)
|
||||
|
||||
message_id_str = ''
|
||||
if message_id:
|
||||
|
@ -2422,6 +2415,16 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
languages_understood = []
|
||||
if actor_json:
|
||||
languages_understood = get_actor_languages_list(actor_json)
|
||||
|
||||
edits_filename = account_dir + box_name + '/' + edits_post_url
|
||||
edits_str = ''
|
||||
if os.path.isfile(edits_filename):
|
||||
edits_json = load_json(edits_filename, 0, 1)
|
||||
if edits_json:
|
||||
edits_str = create_edits_html(edits_json, post_json_object,
|
||||
translate, timezone, system_language,
|
||||
languages_understood)
|
||||
|
||||
content_str = get_content_from_post(post_json_object, system_language,
|
||||
languages_understood)
|
||||
|
||||
|
|
Loading…
Reference in New Issue