epicyon/webapp_welcome.py

106 lines
4.0 KiB
Python
Raw Normal View History

2021-02-24 18:44:26 +00:00
__filename__ = "webapp_welcome.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.2.0"
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
2021-02-24 18:44:26 +00:00
__status__ = "Production"
2021-06-26 11:27:14 +00:00
__module_group__ = "Onboarding"
2021-02-24 18:44:26 +00:00
import os
from shutil import copyfile
2021-12-26 14:08:58 +00:00
from utils import get_config_param
2021-12-27 15:43:22 +00:00
from utils import remove_html
2021-12-26 12:02:29 +00:00
from utils import acct_dir
2021-12-29 21:55:09 +00:00
from webapp_utils import html_header_with_external_style
from webapp_utils import html_footer
from markdown import markdown_to_html
2021-02-24 18:44:26 +00:00
2021-12-29 21:55:09 +00:00
def is_welcome_screen_complete(base_dir: str,
nickname: str, domain: str) -> bool:
2021-02-24 21:17:08 +00:00
"""Returns true if the welcome screen is complete for the given account
"""
2021-12-26 12:02:29 +00:00
accountPath = acct_dir(base_dir, nickname, domain)
2021-02-24 21:17:08 +00:00
if not os.path.isdir(accountPath):
return
completeFilename = accountPath + '/.welcome_complete'
return os.path.isfile(completeFilename)
2021-12-29 21:55:09 +00:00
def welcome_screen_is_complete(base_dir: str,
nickname: str, domain: str) -> None:
2021-02-25 16:55:40 +00:00
"""Indicates that the welcome screen has been shown for a given account
"""
2021-12-26 12:02:29 +00:00
accountPath = acct_dir(base_dir, nickname, domain)
2021-02-25 16:55:40 +00:00
if not os.path.isdir(accountPath):
return
completeFilename = accountPath + '/.welcome_complete'
2021-06-22 12:27:10 +00:00
with open(completeFilename, 'w+') as completeFile:
completeFile.write('\n')
2021-02-25 16:55:40 +00:00
2021-12-29 21:55:09 +00:00
def html_welcome_screen(base_dir: str, nickname: str,
language: str, translate: {},
theme_name: str,
currScreen='welcome') -> str:
2021-02-24 18:44:26 +00:00
"""Returns the welcome screen
"""
# set a custom background for the welcome screen
2021-12-25 16:17:53 +00:00
if os.path.isfile(base_dir + '/accounts/welcome-background-custom.jpg'):
if not os.path.isfile(base_dir + '/accounts/welcome-background.jpg'):
copyfile(base_dir + '/accounts/welcome-background-custom.jpg',
base_dir + '/accounts/welcome-background.jpg')
2021-02-24 18:44:26 +00:00
welcomeText = 'Welcome to Epicyon'
2021-12-25 16:17:53 +00:00
welcomeFilename = base_dir + '/accounts/' + currScreen + '.md'
2021-02-24 18:44:26 +00:00
if not os.path.isfile(welcomeFilename):
2021-02-27 10:27:39 +00:00
defaultFilename = None
2021-12-25 23:35:50 +00:00
if theme_name:
2021-02-27 10:27:39 +00:00
defaultFilename = \
2021-12-25 23:35:50 +00:00
base_dir + '/theme/' + theme_name + '/welcome/' + \
2021-02-27 10:27:39 +00:00
'welcome_' + language + '.md'
if not os.path.isfile(defaultFilename):
defaultFilename = None
if not defaultFilename:
defaultFilename = \
2021-12-25 16:17:53 +00:00
base_dir + '/defaultwelcome/' + \
2021-02-27 10:27:39 +00:00
currScreen + '_' + language + '.md'
2021-02-24 21:22:32 +00:00
if not os.path.isfile(defaultFilename):
2021-02-25 10:37:20 +00:00
defaultFilename = \
2021-12-25 16:17:53 +00:00
base_dir + '/defaultwelcome/' + currScreen + '_en.md'
2021-02-24 21:22:32 +00:00
copyfile(defaultFilename, welcomeFilename)
instanceTitle = \
2021-12-26 14:08:58 +00:00
get_config_param(base_dir, 'instanceTitle')
if not instanceTitle:
instanceTitle = 'Epicyon'
2021-02-24 18:44:26 +00:00
if os.path.isfile(welcomeFilename):
2021-02-25 10:37:20 +00:00
with open(welcomeFilename, 'r') as welcomeFile:
welcomeText = welcomeFile.read()
welcomeText = welcomeText.replace('INSTANCE', instanceTitle)
2021-12-29 21:55:09 +00:00
welcomeText = markdown_to_html(remove_html(welcomeText))
2021-02-24 18:44:26 +00:00
welcomeForm = ''
2021-12-25 16:17:53 +00:00
cssFilename = base_dir + '/epicyon-welcome.css'
if os.path.isfile(base_dir + '/welcome.css'):
cssFilename = base_dir + '/welcome.css'
2021-02-24 18:44:26 +00:00
2021-12-29 21:55:09 +00:00
welcomeForm = \
html_header_with_external_style(cssFilename, instanceTitle, None)
2021-02-25 17:06:07 +00:00
welcomeForm += \
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" ' + \
'action="/users/' + nickname + '/profiledata">\n'
2021-02-24 18:44:26 +00:00
welcomeForm += '<div class="container">' + welcomeText + '</div>\n'
welcomeForm += ' <div class="container next">\n'
2021-02-25 17:06:07 +00:00
welcomeForm += \
' <button type="submit" class="button" ' + \
'name="previewAvatar">' + translate['Next'] + '</button>\n'
2021-02-24 18:44:26 +00:00
welcomeForm += ' </div>\n'
welcomeForm += '</div>\n'
2021-02-25 17:06:07 +00:00
welcomeForm += '</form>\n'
2021-12-29 21:55:09 +00:00
welcomeForm += html_footer()
2021-02-24 18:44:26 +00:00
return welcomeForm