epicyon/webapp_welcome_final.py

81 lines
3.1 KiB
Python
Raw Normal View History

2021-02-25 16:55:40 +00:00
__filename__ = "webapp_welcome_final.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-25 16:55:40 +00:00
__status__ = "Production"
2021-06-26 11:27:14 +00:00
__module_group__ = "Onboarding"
2021-02-25 16:55:40 +00:00
import os
from shutil import copyfile
2021-02-25 19:15:04 +00:00
from utils import removeHtml
2021-02-25 16:55:40 +00:00
from utils import getConfigParam
from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter
from markdown import markdownToHtml
2021-02-25 16:55:40 +00:00
2021-12-25 16:17:53 +00:00
def htmlWelcomeFinal(base_dir: str, nickname: str, domain: str,
2021-12-26 10:00:46 +00:00
http_prefix: str, domain_full: str,
2021-02-27 10:27:39 +00:00
language: str, translate: {},
2021-12-25 23:35:50 +00:00
theme_name: str) -> str:
2021-02-25 16:55:40 +00:00
"""Returns the final welcome screen after first login
"""
# 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-25 16:55:40 +00:00
finalText = 'Welcome to Epicyon'
2021-12-25 16:17:53 +00:00
finalFilename = base_dir + '/accounts/welcome_final.md'
2021-02-25 16:55:40 +00:00
if not os.path.isfile(finalFilename):
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
'final_' + 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/final_' + language + '.md'
2021-02-25 16:55:40 +00:00
if not os.path.isfile(defaultFilename):
2021-12-25 16:17:53 +00:00
defaultFilename = base_dir + '/defaultwelcome/final_en.md'
2021-02-25 16:55:40 +00:00
copyfile(defaultFilename, finalFilename)
instanceTitle = \
2021-12-25 16:17:53 +00:00
getConfigParam(base_dir, 'instanceTitle')
if not instanceTitle:
instanceTitle = 'Epicyon'
2021-02-25 16:55:40 +00:00
if os.path.isfile(finalFilename):
with open(finalFilename, 'r') as finalFile:
finalText = finalFile.read()
finalText = finalText.replace('INSTANCE', instanceTitle)
finalText = markdownToHtml(removeHtml(finalText))
2021-02-25 16:55:40 +00:00
finalForm = ''
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-25 16:55:40 +00:00
finalForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None)
2021-02-25 16:55:40 +00:00
finalForm += \
2021-07-06 12:50:38 +00:00
'<div class="container">' + finalText + '</div>\n' + \
2021-02-25 16:55:40 +00:00
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" ' + \
2021-07-06 12:50:38 +00:00
'action="/users/' + nickname + '/profiledata">\n' + \
'<div class="container next">\n' + \
2021-02-25 16:55:40 +00:00
' <button type="submit" class="button" ' + \
2021-07-06 12:50:38 +00:00
'name="previewAvatar">' + translate['Go Back'] + '</button>\n' + \
2021-02-25 16:55:40 +00:00
' <button type="submit" class="button" ' + \
2021-07-06 12:50:38 +00:00
'name="welcomeCompleteButton">' + translate['Next'] + '</button>\n' + \
'</div>\n'
2021-02-25 16:55:40 +00:00
finalForm += '</form>\n'
finalForm += htmlFooter()
return finalForm