From 0d291b929277a2234139cb31a602f2bb93c6f57b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 18 Jul 2024 13:40:00 +0100 Subject: [PATCH] Tidying --- utils.py | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/utils.py b/utils.py index 951d7b6d9..fcdd20255 100644 --- a/utils.py +++ b/utils.py @@ -473,16 +473,18 @@ def get_content_from_post(post_json_object: {}, system_language: str, # is there a contentMap/summaryMap entry for one of # the understood languages? for lang in languages_understood: - 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('&', '&') - # remove underlines - content = content.replace('', '') - content = content.replace('', '') - return standardize_text(content) + if not this_post_json[map_dict].get(lang): + continue + map_lang = this_post_json[map_dict][lang] + if not isinstance(map_lang, str): + continue + content = map_lang + content = remove_markup_tag(content, 'pre') + content = content.replace('&', '&') + # remove underlines + content = content.replace('', '') + content = content.replace('', '') + return standardize_text(content) else: if isinstance(this_post_json[content_type], str): content = this_post_json[content_type] @@ -839,17 +841,22 @@ def is_editor(base_dir: str, nickname: str) -> bool: return True return False - with open(editors_file, 'r', encoding='utf-8') as fp_editors: - lines = fp_editors.readlines() - if len(lines) == 0: - admin_name = get_config_param(base_dir, 'admin') - if admin_name: - if admin_name == nickname: - return True - for editor in lines: - editor = editor.strip('\n').strip('\r') - if editor == nickname: + lines = [] + try: + with open(editors_file, 'r', encoding='utf-8') as fp_editors: + lines = fp_editors.readlines() + except OSError: + print('EX: is_editor unable to read ' + editors_file) + + if len(lines) == 0: + admin_name = get_config_param(base_dir, 'admin') + if admin_name: + if admin_name == nickname: return True + for editor in lines: + editor = editor.strip('\n').strip('\r') + if editor == nickname: + return True return False