From 830bab130e659e0c631dff322a53e7f541113216 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 25 Feb 2021 10:37:20 +0000 Subject: [PATCH] Allow for a series of welcome screens --- defaultwelcome/profile_en.md | 3 + defaultwelcome/{en.md => welcome_en.md} | 0 webapp_welcome.py | 23 ++++++-- webapp_welcome_profile.py | 73 +++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 defaultwelcome/profile_en.md rename defaultwelcome/{en.md => welcome_en.md} (100%) create mode 100644 webapp_welcome_profile.py diff --git a/defaultwelcome/profile_en.md b/defaultwelcome/profile_en.md new file mode 100644 index 000000000..4f00d8ae1 --- /dev/null +++ b/defaultwelcome/profile_en.md @@ -0,0 +1,3 @@ +# Account Setup + +Add your avatar image, name and description. Use a small avatar image (eg. 128x128 pixels) so that it's quick to download. diff --git a/defaultwelcome/en.md b/defaultwelcome/welcome_en.md similarity index 100% rename from defaultwelcome/en.md rename to defaultwelcome/welcome_en.md diff --git a/webapp_welcome.py b/webapp_welcome.py index ff75ede00..b3acadd31 100644 --- a/webapp_welcome.py +++ b/webapp_welcome.py @@ -38,7 +38,9 @@ def welcomeScreenIsComplete(baseDir: str, nickname: str, domain: str) -> None: def htmlWelcomeScreen(baseDir: str, - language: str, translate: {}) -> str: + language: str, translate: {}, + currScreen='welcome', + nextScreen=None, prevScreen=None) -> str: """Returns the welcome screen """ # set a custom background for the welcome screen @@ -47,15 +49,20 @@ def htmlWelcomeScreen(baseDir: str, copyfile(baseDir + '/accounts/welcome-background-custom.jpg', baseDir + '/accounts/welcome-background.jpg') + if not nextScreen: + nextScreen = 'welcome_profile' + welcomeText = 'Welcome to Epicyon' - welcomeFilename = baseDir + '/accounts/welcome.md' + welcomeFilename = baseDir + '/accounts/' + currScreen + '.md' if not os.path.isfile(welcomeFilename): - defaultFilename = baseDir + '/defaultwelcome/' + language + '.md' + defaultFilename = \ + baseDir + '/defaultwelcome/' + currScreen + '_' + language + '.md' if not os.path.isfile(defaultFilename): - defaultFilename = baseDir + '/defaultwelcome/en.md' + defaultFilename = \ + baseDir + '/defaultwelcome/' + currScreen + '_en.md' copyfile(defaultFilename, welcomeFilename) if os.path.isfile(welcomeFilename): - with open(baseDir + '/accounts/welcome.md', 'r') as welcomeFile: + with open(welcomeFilename, 'r') as welcomeFile: welcomeText = markdownToHtml(welcomeFile.read()) welcomeForm = '' @@ -68,7 +75,11 @@ def htmlWelcomeScreen(baseDir: str, welcomeForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) welcomeForm += '
' + welcomeText + '
\n' welcomeForm += ' \n' welcomeForm += '\n' diff --git a/webapp_welcome_profile.py b/webapp_welcome_profile.py new file mode 100644 index 000000000..901fe5555 --- /dev/null +++ b/webapp_welcome_profile.py @@ -0,0 +1,73 @@ +__filename__ = "webapp_welcome_profile.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 utils import getImageExtensions +from webapp_utils import htmlHeaderWithExternalStyle +from webapp_utils import htmlFooter +from webapp_utils import markdownToHtml + + +def htmlWelcomeProfile(baseDir: str, nickname: str, domain: str, + httpPrefix: str, domainFull: str, + language: str, translate: {}, + prevScreen='welcome') -> str: + """Returns the welcome profile screen to set avatar and bio + """ + # 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') + + profileText = 'Welcome to Epicyon' + profileFilename = baseDir + '/accounts/welcome_profile.md' + if not os.path.isfile(profileFilename): + defaultFilename = \ + baseDir + '/defaultwelcome/profile_' + language + '.md' + if not os.path.isfile(defaultFilename): + defaultFilename = baseDir + '/defaultwelcome/profile_en.md' + copyfile(defaultFilename, profileFilename) + if os.path.isfile(profileFilename): + with open(profileFilename, 'r') as profileFile: + profileText = markdownToHtml(profileFile.read()) + + profileForm = '' + cssFilename = baseDir + '/epicyon-welcome.css' + if os.path.isfile(baseDir + '/welcome.css'): + cssFilename = baseDir + '/welcome.css' + + instanceTitle = \ + getConfigParam(baseDir, 'instanceTitle') + profileForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) + + # get the url of the avatar + for ext in getImageExtensions(): + avatarFilename = \ + baseDir + '/accounts/' + nickname + '@' + domain + '/avatar.' + ext + if os.path.isfile(avatarFilename): + break + avatarUrl = \ + httpPrefix + '://' + domainFull + \ + '/users/' + nickname + '/avatar.' + ext + + profileForm += '
\n' + profileForm += '\n' + profileForm += '
\n' + profileForm += '
' + profileText + '
\n' + profileForm += ' \n' + profileForm += '\n' + profileForm += htmlFooter() + return profileForm