__filename__ = "webapp_accesskeys.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.5.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Accessibility"
import os
from utils import data_dir
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
from webapp_utils import get_banner_file
def load_access_keys_for_accounts(base_dir: str, key_shortcuts: {},
access_keys_template: {}) -> None:
"""Loads key shortcuts for each account
"""
dir_str = data_dir(base_dir)
for _, dirs, _ in os.walk(dir_str):
for acct in dirs:
if not is_account_dir(acct):
continue
account_dir = os.path.join(dir_str, 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(base_dir: str,
nickname: str, domain: str,
translate: {}, access_keys: {},
default_access_keys: {},
default_timeline: str, theme: 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
timeline_key = access_keys['menuTimeline']
submit_key = access_keys['submitButton']
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')
preload_images = []
access_keys_form = \
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
access_keys_form += \
'
' + translate['These access keys may be used'] + \ '
' access_keys_form += ' \n' access_keys_form += '