epicyon/webapp_welcome_profile.py

112 lines
4.3 KiB
Python
Raw Normal View History

2021-02-25 10:37:20 +00:00
__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
2021-02-25 12:17:41 +00:00
from utils import loadJson
2021-02-25 10:37:20 +00:00
from utils import getConfigParam
from utils import getImageExtensions
2021-02-25 12:17:41 +00:00
from utils import getImageFormats
2021-02-25 10:37:20 +00:00
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,
2021-02-25 12:17:41 +00:00
language: str, translate: {}) -> str:
2021-02-25 10:37:20 +00:00
"""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
2021-02-25 12:17:41 +00:00
imageFormats = getImageFormats()
2021-02-25 13:26:09 +00:00
profileForm += '<div class="container">' + profileText + '</div>\n'
2021-02-25 12:17:41 +00:00
profileForm += \
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" ' + \
2021-02-25 14:53:19 +00:00
'action="/users/' + nickname + '/profiledata">\n'
2021-02-25 12:36:06 +00:00
profileForm += '<div class="container">\n'
profileForm += ' <center>\n'
profileForm += ' <img class="welcomeavatar" src="'
2021-02-25 12:17:41 +00:00
profileForm += avatarUrl + '"><br>\n'
2021-02-25 12:36:06 +00:00
profileForm += ' <input type="file" id="avatar" name="avatar" '
2021-02-25 12:17:41 +00:00
profileForm += 'accept="' + imageFormats + '">\n'
2021-02-25 12:36:06 +00:00
profileForm += ' </center>\n'
profileForm += '</div>\n'
2021-02-25 12:17:41 +00:00
2021-02-25 13:26:09 +00:00
profileForm += '<center>\n'
profileForm += \
' <button type="submit" class="button" ' + \
'name="previewAvatar">' + translate['Preview'] + '</button> '
profileForm += '</center>\n'
2021-02-25 12:17:41 +00:00
actorFilename = baseDir + '/accounts/' + nickname + '@' + domain + '.json'
actorJson = loadJson(actorFilename)
displayNickname = actorJson['name']
2021-02-25 12:36:06 +00:00
profileForm += '<div class="container">\n'
2021-02-25 12:17:41 +00:00
profileForm += ' <label class="labels">' + \
2021-02-25 12:24:26 +00:00
translate['Nickname'] + '</label><br>\n'
2021-02-25 12:17:41 +00:00
profileForm += ' <input type="text" name="displayNickname" value="' + \
displayNickname + '"><br>\n'
bioStr = \
actorJson['summary'].replace('<p>', '').replace('</p>', '')
profileForm += ' <label class="labels">' + \
2021-02-25 12:24:26 +00:00
translate['Your bio'] + '</label><br>\n'
2021-02-25 12:17:41 +00:00
profileForm += ' <textarea id="message" name="bio" ' + \
2021-02-25 13:10:03 +00:00
'style="height:130px">' + bioStr + '</textarea>\n'
2021-02-25 12:36:06 +00:00
profileForm += '</div>\n'
2021-02-25 12:17:41 +00:00
2021-02-25 12:36:06 +00:00
profileForm += '<div class="container next">\n'
2021-02-25 12:24:26 +00:00
profileForm += \
' <button type="submit" class="button" ' + \
2021-02-25 16:55:40 +00:00
'name="initialWelcomeScreen">' + translate['Go Back'] + '</button> '
2021-02-25 12:24:26 +00:00
profileForm += \
' <button type="submit" class="button" ' + \
2021-02-25 16:55:40 +00:00
'name="finalWelcomeScreen">' + translate['Next'] + '</button>\n'
2021-02-25 12:36:06 +00:00
profileForm += '</div>\n'
2021-02-25 12:24:26 +00:00
2021-02-25 12:17:41 +00:00
profileForm += '</form>\n'
2021-02-25 10:37:20 +00:00
profileForm += htmlFooter()
return profileForm