__filename__ = "webapp_accesskeys.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.3.0" __maintainer__ = "Bob Mottram" __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Accessibility" import os from utils import is_account_dir from utils import load_json from utils import get_config_param from utils import acct_dir from webapp_utils import html_header_with_external_style from webapp_utils import html_footer def load_access_keys_for_accounts(base_dir: str, key_shortcuts: {}, access_keys_template: {}) -> None: """Loads key shortcuts for each account """ for _, dirs, _ in os.walk(base_dir + '/accounts'): for acct in dirs: if not is_account_dir(acct): continue account_dir = os.path.join(base_dir + '/accounts', acct) access_keys_filename = account_dir + '/access_keys.json' if not os.path.isfile(access_keys_filename): continue nickname = acct.split('@')[0] access_keys = load_json(access_keys_filename) if access_keys: key_shortcuts[nickname] = access_keys_template.copy() for variable_name, _ in access_keys_template.items(): if access_keys.get(variable_name): key_shortcuts[nickname][variable_name] = \ access_keys[variable_name] break def html_access_keys(css_cache: {}, base_dir: str, nickname: str, domain: str, translate: {}, access_keys: {}, default_access_keys: {}, default_timeline: str) -> str: """Show and edit key shortcuts """ access_keys_filename = \ acct_dir(base_dir, nickname, domain) + '/access_keys.json' if os.path.isfile(access_keys_filename): access_keys_from_file = load_json(access_keys_filename) if access_keys_from_file: access_keys = access_keys_from_file access_keys_form = '' css_filename = base_dir + '/epicyon-profile.css' if os.path.isfile(base_dir + '/epicyon.css'): css_filename = base_dir + '/epicyon.css' instance_title = \ get_config_param(base_dir, 'instanceTitle') access_keys_form = \ html_header_with_external_style(css_filename, instance_title, None) access_keys_form += '
\n' access_keys_form += \ '

' + translate['Key Shortcuts'] + '

\n' access_keys_form += \ '

' + translate['These access keys may be used'] + \ '

' access_keys_form += '
\n' timeline_key = access_keys['menuTimeline'] submit_key = access_keys['submitButton'] access_keys_form += \ '
\n' + \ ' \n' + \ ' \n
\n' access_keys_form += ' \n' access_keys_form += ' \n' access_keys_form += ' \n' access_keys_form += ' \n' access_keys_form += ' \n' access_keys_form += ' \n' for variable_name, key in default_access_keys.items(): if not translate.get(variable_name): continue key_str = '' key_str += \ '' if access_keys.get(variable_name): key = access_keys[variable_name] if len(key) > 1: key = key[0] key_str += \ '\n' access_keys_form += key_str access_keys_form += ' \n' access_keys_form += '
' key_str += '
\n' access_keys_form += '
\n' access_keys_form += '
\n' access_keys_form += html_footer() return access_keys_form