38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
import json
|
|
from flask import session
|
|
import sanitize
|
|
import config_utils
|
|
import factory
|
|
import settings
|
|
|
|
|
|
def collect_tokens(cfg):
|
|
tokens = config_utils.collect_layout_tokens(cfg)
|
|
blank = [{'value': '', 'label': '-- Select Timezone --'}]
|
|
tokens['PREF_EMAIL'] = session.get('email_address', '')
|
|
tokens['PREF_TIMEZONE'] = session.get('timezone', '')
|
|
tokens['TIMEZONE_OPTIONS'] = json.dumps(blank + [{'value': tz, 'label': tz} for tz in sanitize.VALID_TIMEZONES])
|
|
|
|
is_initial_manager = session.get('email_address', '').lower() == settings.get_initial_manager_email()
|
|
if is_initial_manager:
|
|
tokens['EMAIL_CHANGE_ACTION'] = '/action/preferences/email_change_direct'
|
|
tokens['EMAIL_CHANGE_BTN_TEXT'] = 'Change Email'
|
|
else:
|
|
tokens['EMAIL_CHANGE_ACTION'] = '/action/preferences/email_change_request'
|
|
tokens['EMAIL_CHANGE_BTN_TEXT'] = 'Submit Request'
|
|
|
|
if not settings.is_single_user():
|
|
account = config_utils.get_account_by_id(session.get('account_id', ''))
|
|
requested = (account or {}).get('requested_email', '')
|
|
else:
|
|
requested = ''
|
|
if requested:
|
|
tokens['PENDING_EMAIL_BAR'] = (
|
|
f'<div class="info-bar info-bar-inline info-bar-warning">'
|
|
f'A request to change email to {factory.e(requested)} is pending approval.'
|
|
f'</div>'
|
|
)
|
|
else:
|
|
tokens['PENDING_EMAIL_BAR'] = ''
|
|
|
|
return tokens
|