Use contentMap within cw list processing

main
Bob Mottram 2022-04-13 15:35:11 +01:00
parent eb5f561294
commit cd02056588
3 changed files with 25 additions and 8 deletions

View File

@ -1016,19 +1016,29 @@ def load_cw_lists(base_dir: str, verbose: bool) -> {}:
def add_cw_from_lists(post_json_object: {}, cw_lists: {}, translate: {},
lists_enabled: str) -> None:
lists_enabled: str, system_language: str) -> None:
"""Adds content warnings by matching the post content
against domains or keywords
"""
if not lists_enabled:
return
if not post_json_object['object'].get('content'):
return
if not post_json_object['object'].get('contentMap'):
return
cw_text = ''
if post_json_object['object'].get('summary'):
cw_text = post_json_object['object']['summary']
content = post_json_object['object']['content']
content = None
if post_json_object['object'].get('contentMap'):
if post_json_object['object']['contentMap'].get(system_language):
content = \
post_json_object['object']['contentMap'][system_language]
if not content:
if post_json_object['object'].get('content'):
content = post_json_object['object']['content']
if not content:
return
for name, item in cw_lists.items():
if name not in lists_enabled:
continue

View File

@ -6504,6 +6504,7 @@ def _test_word_similarity() -> None:
def _test_add_cw_lists(base_dir: str) -> None:
print('test_add_CW_from_lists')
translate = {}
system_language = "en"
cw_lists = load_cw_lists(base_dir, True)
assert cw_lists
@ -6514,7 +6515,8 @@ def _test_add_cw_lists(base_dir: str) -> None:
"content": ""
}
}
add_cw_from_lists(post_json_object, cw_lists, translate, 'Murdoch press')
add_cw_from_lists(post_json_object, cw_lists, translate, 'Murdoch press',
system_language)
assert post_json_object['object']['sensitive'] is False
assert post_json_object['object']['summary'] is None
@ -6522,10 +6524,13 @@ def _test_add_cw_lists(base_dir: str) -> None:
"object": {
"sensitive": False,
"summary": None,
"content": "Blah blah news.co.uk blah blah"
"contentMap": {
"en": "Blah blah news.co.uk blah blah"
}
}
}
add_cw_from_lists(post_json_object, cw_lists, translate, 'Murdoch press')
add_cw_from_lists(post_json_object, cw_lists, translate, 'Murdoch press',
system_language)
assert post_json_object['object']['sensitive'] is True
assert post_json_object['object']['summary'] == "Murdoch Press"
@ -6536,7 +6541,8 @@ def _test_add_cw_lists(base_dir: str) -> None:
"content": "Blah blah news.co.uk blah blah"
}
}
add_cw_from_lists(post_json_object, cw_lists, translate, 'Murdoch press')
add_cw_from_lists(post_json_object, cw_lists, translate, 'Murdoch press',
system_language)
assert post_json_object['object']['sensitive'] is True
assert post_json_object['object']['summary'] == \
"Murdoch Press / Existing CW"

View File

@ -1936,7 +1936,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
container_class = 'container dm'
# add any content warning from the cwlists directory
add_cw_from_lists(post_json_object, cw_lists, translate, lists_enabled)
add_cw_from_lists(post_json_object, cw_lists, translate, lists_enabled,
system_language)
post_is_sensitive = False
if post_json_object['object'].get('sensitive'):