epicyon/webapp_welcome.py

63 lines
2.4 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"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import os
from shutil import copyfile
from utils import getConfigParam
from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter
2021-02-24 19:04:51 +00:00
from webapp_utils import markdownToHtml
2021-02-24 18:44:26 +00:00
def welcomeScreenShown(baseDir: str, nickname: str, domain: str):
"""Indicates that the welcome screen has been shown for a given account
"""
shownFilename = baseDir + '/accounts/.welcome_shown'
shownFile = open(shownFilename, 'w+')
if shownFile:
shownFile.write('\n')
shownFile.close()
def htmlWelcomeScreen(baseDir: str, nickname: str, domain: str,
language: str, translate: {}) -> str:
"""Returns the welcome screen
"""
# set a custom background for the welcome screen
if os.path.isfile(baseDir + '/accounts/welcome-background-custom.jpg'):
if not os.path.isfile(baseDir + '/accounts/welcome-background.jpg'):
copyfile(baseDir + '/accounts/welcome-background-custom.jpg',
baseDir + '/accounts/welcome-background.jpg')
welcomeText = 'Welcome to Epicyon'
2021-02-24 20:37:59 +00:00
welcomeFilename = baseDir + '/accounts/welcome.md'
2021-02-24 18:44:26 +00:00
if not os.path.isfile(welcomeFilename):
2021-02-24 20:37:59 +00:00
defaultFilename = baseDir + '/defaultwelcome/' + language + '.md'
2021-02-24 18:44:26 +00:00
if os.path.isfile(defaultFilename):
copyfile(defaultFilename, welcomeFilename)
if os.path.isfile(welcomeFilename):
2021-02-24 20:37:59 +00:00
with open(baseDir + '/accounts/welcome.md', 'r') as welcomeFile:
2021-02-24 19:04:51 +00:00
welcomeText = markdownToHtml(welcomeFile.read())
2021-02-24 18:44:26 +00:00
welcomeForm = ''
cssFilename = baseDir + '/epicyon-welcome.css'
if os.path.isfile(baseDir + '/welcome.css'):
cssFilename = baseDir + '/welcome.css'
instanceTitle = \
getConfigParam(baseDir, 'instanceTitle')
welcomeForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle)
welcomeForm += '<div class="container">' + welcomeText + '</div>\n'
welcomeForm += ' <div class="container next">\n'
2021-02-24 20:45:38 +00:00
welcomeForm += ' <a href="/welcome_profile">'
welcomeForm += ' <button>' + translate['Next'] + '</button></a>\n'
2021-02-24 18:44:26 +00:00
welcomeForm += ' </div>\n'
welcomeForm += '</div>\n'
welcomeForm += htmlFooter()
return welcomeForm