Move edit functions to utils module

merge-requests/30/head
Bob Mottram 2021-07-22 17:58:59 +01:00
parent e66891f8ab
commit e1a9041586
4 changed files with 181 additions and 199 deletions

View File

@ -18,6 +18,7 @@ from utils import acctDir
from webapp_utils import getBannerFile from webapp_utils import getBannerFile
from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter from webapp_utils import htmlFooter
from webapp_utils import editTextField
def _htmlFollowingDataList(baseDir: str, nickname: str, def _htmlFollowingDataList(baseDir: str, nickname: str,
@ -277,16 +278,8 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
pathBase = pathBase.replace('/newfollowers', '').replace('/newdm', '') pathBase = pathBase.replace('/newfollowers', '').replace('/newdm', '')
newPostImageSection = ' <div class="container">' newPostImageSection = ' <div class="container">'
if not path.endswith('/newevent'):
newPostImageSection += \ newPostImageSection += \
' <label class="labels">' + \ editTextField(translate['Image description'], 'imageDescription', '')
translate['Image description'] + '</label>\n'
else:
newPostImageSection += \
' <label class="labels">' + \
translate['Event banner image description'] + '</label>\n'
newPostImageSection += \
' <input type="text" name="imageDescription">\n'
if path.endswith('/newevent'): if path.endswith('/newevent'):
newPostImageSection += \ newPostImageSection += \
@ -379,15 +372,10 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
endpoint = 'newshare' endpoint = 'newshare'
extraFields = '<div class="container">\n' extraFields = '<div class="container">\n'
extraFields += \ extraFields += \
' <label class="labels">' + \ editTextField(translate['Type of shared item. eg. hat'] + ':',
translate['Type of shared item. eg. hat'] + ':</label>\n' 'itemType', '')
extraFields += \ catStr = translate['Category of shared item. eg. clothing']
' <input type="text" class="itemType" name="itemType">\n' extraFields += editTextField(catStr + ':', 'category', '')
extraFields += \
' <br><label class="labels">' + \
translate['Category of shared item. eg. clothing'] + ':</label>\n'
extraFields += \
' <input type="text" class="category" name="category">\n'
extraFields += \ extraFields += \
' <br><label class="labels">' + \ ' <br><label class="labels">' + \
translate['Duration of listing in days'] + ':</label>\n' translate['Duration of listing in days'] + ':</label>\n'
@ -395,10 +383,8 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
'min="1" max="365" step="1" value="14">\n' 'min="1" max="365" step="1" value="14">\n'
extraFields += '</div>\n' extraFields += '</div>\n'
extraFields += '<div class="container">\n' extraFields += '<div class="container">\n'
extraFields += \ cityOrLocStr = translate['City or location of the shared item']
'<label class="labels">' + \ extraFields += editTextField(cityOrLocStr + ':', 'location', '')
translate['City or location of the shared item'] + ':</label>\n'
extraFields += '<input type="text" name="location">\n'
extraFields += '</div>\n' extraFields += '</div>\n'
citationsStr = '' citationsStr = ''
@ -561,16 +547,8 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
'autocomplete="on"></textarea>\n' 'autocomplete="on"></textarea>\n'
dateAndLocation += '</div>\n' dateAndLocation += '</div>\n'
dateAndLocation += '<div class="container">\n' dateAndLocation += '<div class="container">\n'
dateAndLocation += '<label class="labels">' + \ dateAndLocation += \
translate['Location'] + ': </label>\n' editTextField(translate['Location'], 'location', '')
dateAndLocation += '<input type="text" name="location">\n'
if endpoint == 'newevent':
dateAndLocation += '<br><label class="labels">' + \
translate['Ticket URL'] + ': </label>\n'
dateAndLocation += '<input type="text" name="ticketUrl">\n'
dateAndLocation += '<br><label class="labels">' + \
translate['Categories'] + ': </label>\n'
dateAndLocation += '<input type="text" name="category">\n'
dateAndLocation += '</div>\n' dateAndLocation += '</div>\n'
instanceTitle = getConfigParam(baseDir, 'instanceTitle') instanceTitle = getConfigParam(baseDir, 'instanceTitle')
@ -712,13 +690,10 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
if mediaInstance and not replyStr: if mediaInstance and not replyStr:
newPostForm += newPostImageSection newPostForm += newPostImageSection
newPostForm += \
' <label class="labels">' + placeholderSubject + '</label><br>'
if not shareDescription: if not shareDescription:
shareDescription = '' shareDescription = ''
newPostForm += \ newPostForm += \
' <input type="text" name="subject" value="' + \ editTextField(placeholderSubject, 'subject', shareDescription)
shareDescription + '">'
newPostForm += '' newPostForm += ''
selectedStr = ' selected' selectedStr = ' selected'

View File

@ -55,69 +55,16 @@ from webapp_utils import htmlFooter
from webapp_utils import addEmojiToDisplayName from webapp_utils import addEmojiToDisplayName
from webapp_utils import getBannerFile from webapp_utils import getBannerFile
from webapp_utils import htmlPostSeparator from webapp_utils import htmlPostSeparator
from webapp_utils import editCheckBox
from webapp_utils import editTextField
from webapp_utils import editTextArea
from webapp_utils import beginEditSection
from webapp_utils import endEditSection
from blog import getBlogAddress from blog import getBlogAddress
from webapp_post import individualPostAsHtml from webapp_post import individualPostAsHtml
from webapp_timeline import htmlIndividualShare from webapp_timeline import htmlIndividualShare
def _beginEditSection(label: str) -> str:
"""returns the html for begining a dropdown section on edit profile screen
"""
return \
' <details><summary class="cw">' + label + '</summary>\n' + \
'<div class="container">'
def _endEditSection() -> str:
"""returns the html for ending a dropdown section on edit profile screen
"""
return ' </div></details>\n'
def _editText(label: str, name: str, value: str = "",
placeholder: str = "") -> str:
"""Returns html for editing a text field
"""
if value is None:
value = ''
placeholderStr = ''
if placeholder:
placeholderStr = ' placeholder="' + placeholder + '"'
return \
'<label class="labels">' + label + '</label><br>\n' + \
' <input type="text" name="' + name + '" value="' + \
value + '"' + placeholderStr + '>\n'
def _editCheckBox(label: str, name: str, checked: bool = False) -> str:
"""Returns html for editing a checkbox field
"""
checkedStr = ''
if checked:
checkedStr = ' checked'
return \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="' + name + '"' + checkedStr + '> ' + label + '<br>\n'
def _editTextArea(label: str, name: str, value: str = "",
height: int = 600,
placeholder: str = "",
spellcheck: bool = False) -> str:
"""Returns html for editing a textarea field
"""
if value is None:
value = ''
return \
'<label class="labels">' + label + '</label><br>\n' + \
' <textarea id="message" placeholder=' + \
'"' + placeholder + '" name="' + name + '" ' + \
'style="height:' + height + 'px" spellcheck="' + \
str(spellcheck).lower() + '">' + \
value + '</textarea>\n'
def htmlProfileAfterSearch(cssCache: {}, def htmlProfileAfterSearch(cssCache: {},
recentPostsCache: {}, maxRecentPosts: int, recentPostsCache: {}, maxRecentPosts: int,
translate: {}, translate: {},
@ -1085,7 +1032,7 @@ def _htmlThemesDropdown(baseDir: str, translate: {}) -> str:
translate['Theme'] + '</label><br>\n' translate['Theme'] + '</label><br>\n'
grayscale = _grayscaleEnabled(baseDir) grayscale = _grayscaleEnabled(baseDir)
themesDropdown += \ themesDropdown += \
_editCheckBox(translate['Grayscale'], 'grayscale', grayscale) editCheckBox(translate['Grayscale'], 'grayscale', grayscale)
themesDropdown += ' <select id="themeDropdown" ' + \ themesDropdown += ' <select id="themeDropdown" ' + \
'name="themeDropdown" class="theme">' 'name="themeDropdown" class="theme">'
for themeName in themes: for themeName in themes:
@ -1101,7 +1048,7 @@ def _htmlThemesDropdown(baseDir: str, translate: {}) -> str:
os.path.isfile(baseDir + '/fonts/custom.otf') or \ os.path.isfile(baseDir + '/fonts/custom.otf') or \
os.path.isfile(baseDir + '/fonts/custom.ttf'): os.path.isfile(baseDir + '/fonts/custom.ttf'):
themesDropdown += \ themesDropdown += \
_editCheckBox(translate['Remove the custom font'], editCheckBox(translate['Remove the custom font'],
'removeCustomFont', False) 'removeCustomFont', False)
themeName = getConfigParam(baseDir, 'theme') themeName = getConfigParam(baseDir, 'theme')
themesDropdown = \ themesDropdown = \
@ -1116,7 +1063,7 @@ def _htmlEditProfileGraphicDesign(baseDir: str, translate: {}) -> str:
""" """
themeFormats = '.zip, .gz' themeFormats = '.zip, .gz'
graphicsStr = _beginEditSection(translate['Graphic Design']) graphicsStr = beginEditSection(translate['Graphic Design'])
graphicsStr += _htmlThemesDropdown(baseDir, translate) graphicsStr += _htmlThemesDropdown(baseDir, translate)
graphicsStr += \ graphicsStr += \
@ -1132,7 +1079,7 @@ def _htmlEditProfileGraphicDesign(baseDir: str, translate: {}) -> str:
' <button type="submit" class="button" ' + \ ' <button type="submit" class="button" ' + \
'name="submitExportTheme">➤</button>\n' 'name="submitExportTheme">➤</button>\n'
graphicsStr += _endEditSection() graphicsStr += endEditSection()
return graphicsStr return graphicsStr
@ -1155,22 +1102,22 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
instanceTitle = \ instanceTitle = \
getConfigParam(baseDir, 'instanceTitle') getConfigParam(baseDir, 'instanceTitle')
instanceStr = _beginEditSection(translate['Instance Settings']) instanceStr = beginEditSection(translate['Instance Settings'])
instanceStr += \ instanceStr += \
_editText(translate['Instance Title'], editTextField(translate['Instance Title'],
'instanceTitle', instanceTitle) 'instanceTitle', instanceTitle)
instanceStr += '<br>\n' instanceStr += '<br>\n'
instanceStr += \ instanceStr += \
_editText(translate['Instance Short Description'], editTextField(translate['Instance Short Description'],
'instanceDescriptionShort', instanceDescriptionShort) 'instanceDescriptionShort', instanceDescriptionShort)
instanceStr += '<br>\n' instanceStr += '<br>\n'
instanceStr += \ instanceStr += \
_editTextArea(translate['Instance Description'], editTextArea(translate['Instance Description'],
'instanceDescription', instanceDescription, 200, 'instanceDescription', instanceDescription, 200,
'', True) '', True)
instanceStr += \ instanceStr += \
_editText(translate['Custom post submit button text'], editTextField(translate['Custom post submit button text'],
'customSubmitText', customSubmitText) 'customSubmitText', customSubmitText)
instanceStr += '<br>\n' instanceStr += '<br>\n'
instanceStr += \ instanceStr += \
@ -1185,51 +1132,51 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
translate['Show numbers of accounts within instance metadata'] translate['Show numbers of accounts within instance metadata']
if getConfigParam(baseDir, "showNodeInfoAccounts"): if getConfigParam(baseDir, "showNodeInfoAccounts"):
instanceStr += \ instanceStr += \
_editCheckBox(nodeInfoStr, 'showNodeInfoAccounts', True) editCheckBox(nodeInfoStr, 'showNodeInfoAccounts', True)
else: else:
instanceStr += \ instanceStr += \
_editCheckBox(nodeInfoStr, 'showNodeInfoAccounts', False) editCheckBox(nodeInfoStr, 'showNodeInfoAccounts', False)
nodeInfoStr = \ nodeInfoStr = \
translate['Show version number within instance metadata'] translate['Show version number within instance metadata']
if getConfigParam(baseDir, "showNodeInfoVersion"): if getConfigParam(baseDir, "showNodeInfoVersion"):
instanceStr += \ instanceStr += \
_editCheckBox(nodeInfoStr, 'showNodeInfoVersion', True) editCheckBox(nodeInfoStr, 'showNodeInfoVersion', True)
else: else:
instanceStr += \ instanceStr += \
_editCheckBox(nodeInfoStr, 'showNodeInfoVersion', False) editCheckBox(nodeInfoStr, 'showNodeInfoVersion', False)
if getConfigParam(baseDir, "verifyAllSignatures"): if getConfigParam(baseDir, "verifyAllSignatures"):
instanceStr += \ instanceStr += \
_editCheckBox(translate['Verify all signatures'], editCheckBox(translate['Verify all signatures'],
'verifyallsignatures', True) 'verifyallsignatures', True)
else: else:
instanceStr += \ instanceStr += \
_editCheckBox(translate['Verify all signatures'], editCheckBox(translate['Verify all signatures'],
'verifyallsignatures', False) 'verifyallsignatures', False)
instanceStr += translate['Enabling broch mode'] + '<br>\n' instanceStr += translate['Enabling broch mode'] + '<br>\n'
if getConfigParam(baseDir, "brochMode"): if getConfigParam(baseDir, "brochMode"):
instanceStr += \ instanceStr += \
_editCheckBox(translate['Broch mode'], 'brochMode', True) editCheckBox(translate['Broch mode'], 'brochMode', True)
else: else:
instanceStr += \ instanceStr += \
_editCheckBox(translate['Broch mode'], 'brochMode', False) editCheckBox(translate['Broch mode'], 'brochMode', False)
# Instance type # Instance type
instanceStr += \ instanceStr += \
' <br><label class="labels">' + \ ' <br><label class="labels">' + \
translate['Type of instance'] + '</label><br>\n' translate['Type of instance'] + '</label><br>\n'
instanceStr += \ instanceStr += \
_editCheckBox(translate['This is a media instance'], editCheckBox(translate['This is a media instance'],
'mediaInstance', mediaInstanceStr) 'mediaInstance', mediaInstanceStr)
instanceStr += \ instanceStr += \
_editCheckBox(translate['This is a blogging instance'], editCheckBox(translate['This is a blogging instance'],
'blogsInstance', blogsInstanceStr) 'blogsInstance', blogsInstanceStr)
instanceStr += \ instanceStr += \
_editCheckBox(translate['This is a news instance'], editCheckBox(translate['This is a news instance'],
'newsInstance', newsInstanceStr) 'newsInstance', newsInstanceStr)
instanceStr += _endEditSection() instanceStr += endEditSection()
# Role assignments section # Role assignments section
moderators = '' moderators = ''
@ -1239,7 +1186,7 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
moderators = f.read() moderators = f.read()
# site moderators # site moderators
roleAssignStr = \ roleAssignStr = \
_beginEditSection(translate['Role Assignment']) + \ beginEditSection(translate['Role Assignment']) + \
' <b><label class="labels">' + \ ' <b><label class="labels">' + \
translate['Moderators'] + '</label></b><br>\n' + \ translate['Moderators'] + '</label></b><br>\n' + \
' ' + \ ' ' + \
@ -1290,12 +1237,12 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
' <textarea id="message" name="artists" ' + \ ' <textarea id="message" name="artists" ' + \
'placeholder="" ' + \ 'placeholder="" ' + \
'style="height:200px" spellcheck="false">' + \ 'style="height:200px" spellcheck="false">' + \
artists + '</textarea>' + _endEditSection() artists + '</textarea>' + endEditSection()
# Video section # Video section
idx = 'Show video previews for the following Peertube sites.' idx = 'Show video previews for the following Peertube sites.'
peertubeStr = \ peertubeStr = \
_beginEditSection(translate['Video Settings']) + \ beginEditSection(translate['Video Settings']) + \
' <b><label class="labels">' + \ ' <b><label class="labels">' + \
translate['Peertube Instances'] + '</label></b>\n' + \ translate['Peertube Instances'] + '</label></b>\n' + \
' <br><label class="labels">' + \ ' <br><label class="labels">' + \
@ -1312,9 +1259,9 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
if not YTReplacementDomain: if not YTReplacementDomain:
YTReplacementDomain = '' YTReplacementDomain = ''
peertubeStr += \ peertubeStr += \
_editText(translate['YouTube Replacement Domain'], editTextField(translate['YouTube Replacement Domain'],
'ytdomain', YTReplacementDomain) 'ytdomain', YTReplacementDomain)
peertubeStr += _endEditSection() peertubeStr += endEditSection()
libretranslateUrl = getConfigParam(baseDir, 'libretranslateUrl') libretranslateUrl = getConfigParam(baseDir, 'libretranslateUrl')
libretranslateApiKey = getConfigParam(baseDir, 'libretranslateApiKey') libretranslateApiKey = getConfigParam(baseDir, 'libretranslateApiKey')
@ -1329,17 +1276,17 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
def _htmlEditProfileDangerZone(translate: {}) -> str: def _htmlEditProfileDangerZone(translate: {}) -> str:
"""danger zone section of Edit Profile screen """danger zone section of Edit Profile screen
""" """
editProfileForm = _beginEditSection(translate['Danger Zone']) editProfileForm = beginEditSection(translate['Danger Zone'])
editProfileForm += \ editProfileForm += \
' <b><label class="labels">' + \ ' <b><label class="labels">' + \
translate['Danger Zone'] + '</label></b><br>\n' translate['Danger Zone'] + '</label></b><br>\n'
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['Deactivate this account'], editCheckBox(translate['Deactivate this account'],
'deactivateThisAccount', False) 'deactivateThisAccount', False)
editProfileForm += _endEditSection() editProfileForm += endEditSection()
return editProfileForm return editProfileForm
@ -1369,14 +1316,14 @@ def _htmlEditProfileSkills(baseDir: str, nickname: str, domain: str,
'" value="" style="width:40%">' + \ '" value="" style="width:40%">' + \
'<input type="range" min="1" max="100" ' + \ '<input type="range" min="1" max="100" ' + \
'class="slider" name="skillValue' + \ 'class="slider" name="skillValue' + \
str(skillCtr) + '" value="50"></p>' + _endEditSection() str(skillCtr) + '" value="50"></p>' + endEditSection()
idx = 'If you want to participate within organizations then you ' + \ idx = 'If you want to participate within organizations then you ' + \
'can indicate some skills that you have and approximate ' + \ 'can indicate some skills that you have and approximate ' + \
'proficiency levels. This helps organizers to construct ' + \ 'proficiency levels. This helps organizers to construct ' + \
'teams with an appropriate combination of skills.' 'teams with an appropriate combination of skills.'
editProfileForm = \ editProfileForm = \
_beginEditSection(translate['Skills']) + \ beginEditSection(translate['Skills']) + \
' <b><label class="labels">' + \ ' <b><label class="labels">' + \
translate['Skills'] + '</label></b><br>\n' + \ translate['Skills'] + '</label></b><br>\n' + \
' <label class="labels">' + \ ' <label class="labels">' + \
@ -1397,12 +1344,12 @@ def _htmlEditProfileGitProjects(baseDir: str, nickname: str, domain: str,
idx = 'List of project names that you wish to receive git patches for' idx = 'List of project names that you wish to receive git patches for'
editProfileForm = \ editProfileForm = \
_beginEditSection(translate['Git Projects']) + \ beginEditSection(translate['Git Projects']) + \
' <label class="labels">' + \ ' <label class="labels">' + \
translate[idx] + '</label>\n' + \ translate[idx] + '</label>\n' + \
' <textarea id="message" name="gitProjects" ' + \ ' <textarea id="message" name="gitProjects" ' + \
'style="height:100px" spellcheck="false">' + \ 'style="height:100px" spellcheck="false">' + \
gitProjectsStr + '</textarea>\n' + _endEditSection() gitProjectsStr + '</textarea>\n' + endEditSection()
return editProfileForm return editProfileForm
@ -1459,7 +1406,7 @@ def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str,
with open(allowedInstancesFilename, 'r') as allowedInstancesFile: with open(allowedInstancesFilename, 'r') as allowedInstancesFile:
allowedInstancesStr = allowedInstancesFile.read() allowedInstancesStr = allowedInstancesFile.read()
editProfileForm = _beginEditSection(translate['Filtering and Blocking']) editProfileForm = beginEditSection(translate['Filtering and Blocking'])
editProfileForm += \ editProfileForm += \
'<label class="labels">' + \ '<label class="labels">' + \
@ -1564,7 +1511,7 @@ def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str,
'style="height:200px" spellcheck="false">' + \ 'style="height:200px" spellcheck="false">' + \
userAgentsBlockedStr + '</textarea>\n' userAgentsBlockedStr + '</textarea>\n'
editProfileForm += _endEditSection() editProfileForm += endEditSection()
return editProfileForm return editProfileForm
@ -1572,7 +1519,7 @@ def _htmlEditProfileChangePassword(translate: {}) -> str:
"""Change password section of edit profile screen """Change password section of edit profile screen
""" """
editProfileForm = \ editProfileForm = \
_beginEditSection(translate['Change Password']) + \ beginEditSection(translate['Change Password']) + \
'<label class="labels">' + translate['Change Password'] + \ '<label class="labels">' + translate['Change Password'] + \
'</label><br>\n' + \ '</label><br>\n' + \
' <input type="password" name="password" ' + \ ' <input type="password" name="password" ' + \
@ -1580,7 +1527,7 @@ def _htmlEditProfileChangePassword(translate: {}) -> str:
'<label class="labels">' + translate['Confirm Password'] + \ '<label class="labels">' + translate['Confirm Password'] + \
'</label><br>\n' + \ '</label><br>\n' + \
' <input type="password" name="passwordconfirm" value="">\n' + \ ' <input type="password" name="passwordconfirm" value="">\n' + \
_endEditSection() endEditSection()
return editProfileForm return editProfileForm
@ -1589,15 +1536,15 @@ def _htmlEditProfileLibreTranslate(translate: {},
libretranslateApiKey: str) -> str: libretranslateApiKey: str) -> str:
"""Change automatic translation settings """Change automatic translation settings
""" """
editProfileForm = _beginEditSection('LibreTranslate') editProfileForm = beginEditSection('LibreTranslate')
editProfileForm += \ editProfileForm += \
_editText('URL', 'libretranslateUrl', libretranslateUrl, editTextField('URL', 'libretranslateUrl', libretranslateUrl,
'http://0.0.0.0:5000') 'http://0.0.0.0:5000')
editProfileForm += \ editProfileForm += \
_editText('API Key', 'libretranslateApiKey', libretranslateApiKey) editTextField('API Key', 'libretranslateApiKey', libretranslateApiKey)
editProfileForm += _endEditSection() editProfileForm += endEditSection()
return editProfileForm return editProfileForm
@ -1607,7 +1554,7 @@ def _htmlEditProfileBackground(newsInstance: bool, translate: {}) -> str:
idx = 'The files attached below should be no larger than ' + \ idx = 'The files attached below should be no larger than ' + \
'10MB in total uploaded at once.' '10MB in total uploaded at once.'
editProfileForm = \ editProfileForm = \
_beginEditSection(translate['Background Images']) + \ beginEditSection(translate['Background Images']) + \
' <label class="labels">' + translate[idx] + '</label><br><br>\n' ' <label class="labels">' + translate[idx] + '</label><br><br>\n'
if not newsInstance: if not newsInstance:
@ -1637,7 +1584,7 @@ def _htmlEditProfileBackground(newsInstance: bool, translate: {}) -> str:
'name="right_col_image"' + \ 'name="right_col_image"' + \
' accept="' + imageFormats + '">\n' ' accept="' + imageFormats + '">\n'
editProfileForm += _endEditSection() editProfileForm += endEditSection()
return editProfileForm return editProfileForm
@ -1655,30 +1602,30 @@ def _htmlEditProfileContactInfo(nickname: str,
translate: {}) -> str: translate: {}) -> str:
"""Contact Information section of edit profile screen """Contact Information section of edit profile screen
""" """
editProfileForm = _beginEditSection(translate['Contact Details']) editProfileForm = beginEditSection(translate['Contact Details'])
editProfileForm += _editText(translate['Email'], editProfileForm += editTextField(translate['Email'],
'email', emailAddress) 'email', emailAddress)
editProfileForm += _editText(translate['XMPP'], editProfileForm += editTextField(translate['XMPP'],
'xmppAddress', xmppAddress) 'xmppAddress', xmppAddress)
editProfileForm += _editText(translate['Matrix'], editProfileForm += editTextField(translate['Matrix'],
'matrixAddress', matrixAddress) 'matrixAddress', matrixAddress)
editProfileForm += _editText('SSB', 'ssbAddress', ssbAddress) editProfileForm += editTextField('SSB', 'ssbAddress', ssbAddress)
editProfileForm += _editText('Tox', 'toxAddress', toxAddress) editProfileForm += editTextField('Tox', 'toxAddress', toxAddress)
editProfileForm += _editText('Briar', 'briarAddress', briarAddress) editProfileForm += editTextField('Briar', 'briarAddress', briarAddress)
editProfileForm += _editText('Jami', 'jamiAddress', jamiAddress) editProfileForm += editTextField('Jami', 'jamiAddress', jamiAddress)
editProfileForm += _editText('Cwtch', 'cwtchAddress', cwtchAddress) editProfileForm += editTextField('Cwtch', 'cwtchAddress', cwtchAddress)
editProfileForm += _editText(translate['PGP Fingerprint'], editProfileForm += editTextField(translate['PGP Fingerprint'],
'openpgp', PGPfingerprint) 'openpgp', PGPfingerprint)
editProfileForm += \ editProfileForm += \
_editTextArea(translate['PGP'], 'pgp', PGPpubKey, 600, editTextArea(translate['PGP'], 'pgp', PGPpubKey, 600,
'-----BEGIN PGP PUBLIC KEY BLOCK-----', False) '-----BEGIN PGP PUBLIC KEY BLOCK-----', False)
editProfileForm += \ editProfileForm += \
'<a href="/users/' + nickname + \ '<a href="/users/' + nickname + \
'/followingaccounts"><label class="labels">' + \ '/followingaccounts"><label class="labels">' + \
translate['Following'] + '</label></a><br>\n' translate['Following'] + '</label></a><br>\n'
editProfileForm += _endEditSection() editProfileForm += endEditSection()
return editProfileForm return editProfileForm
@ -1691,25 +1638,25 @@ def _htmlEditProfileOptions(manuallyApprovesFollowers: str,
""" """
editProfileForm = ' <div class="container">\n' editProfileForm = ' <div class="container">\n'
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['Approve follower requests'], editCheckBox(translate['Approve follower requests'],
'approveFollowers', manuallyApprovesFollowers) 'approveFollowers', manuallyApprovesFollowers)
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['This is a bot account'], editCheckBox(translate['This is a bot account'],
'isBot', isBot) 'isBot', isBot)
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['This is a group account'], editCheckBox(translate['This is a group account'],
'isGroup', isGroup) 'isGroup', isGroup)
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['Only people I follow can send me DMs'], editCheckBox(translate['Only people I follow can send me DMs'],
'followDMs', followDMs) 'followDMs', followDMs)
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['Remove Twitter posts'], editCheckBox(translate['Remove Twitter posts'],
'removeTwitter', removeTwitter) 'removeTwitter', removeTwitter)
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['Notify when posts are liked'], editCheckBox(translate['Notify when posts are liked'],
'notifyLikes', notifyLikes) 'notifyLikes', notifyLikes)
editProfileForm += \ editProfileForm += \
_editCheckBox(translate["Don't show the Like button"], editCheckBox(translate["Don't show the Like button"],
'hideLikeButton', hideLikeButton) 'hideLikeButton', hideLikeButton)
editProfileForm += ' </div>\n' editProfileForm += ' </div>\n'
return editProfileForm return editProfileForm
@ -1751,7 +1698,8 @@ def _htmlEditProfileMain(baseDir: str, displayNickname: str, bioStr: str,
editProfileForm = ' <div class="container">\n' editProfileForm = ' <div class="container">\n'
editProfileForm += \ editProfileForm += \
_editText(translate['Nickname'], 'displayNickname', displayNickname) editTextField(translate['Nickname'], 'displayNickname',
displayNickname)
editProfileForm += \ editProfileForm += \
' <label class="labels">' + \ ' <label class="labels">' + \
@ -1770,7 +1718,8 @@ def _htmlEditProfileMain(baseDir: str, displayNickname: str, bioStr: str,
occupationName = getOccupationName(actorJson) occupationName = getOccupationName(actorJson)
editProfileForm += \ editProfileForm += \
_editText(translate['Occupation'], 'occupationName', occupationName) editTextField(translate['Occupation'], 'occupationName',
occupationName)
alsoKnownAsStr = '' alsoKnownAsStr = ''
if actorJson.get('alsoKnownAs'): if actorJson.get('alsoKnownAs'):
@ -1783,24 +1732,24 @@ def _htmlEditProfileMain(baseDir: str, displayNickname: str, bioStr: str,
alsoKnownAsStr += altActor alsoKnownAsStr += altActor
editProfileForm += \ editProfileForm += \
_editText(translate['Other accounts'], 'alsoKnownAs', editTextField(translate['Other accounts'], 'alsoKnownAs',
alsoKnownAsStr, 'https://...') alsoKnownAsStr, 'https://...')
editProfileForm += \ editProfileForm += \
_editText(translate['Moved to new account address'], 'movedTo', editTextField(translate['Moved to new account address'], 'movedTo',
movedTo, 'https://...') movedTo, 'https://...')
editProfileForm += \ editProfileForm += \
_editText(translate['Donations link'], 'donateUrl', editTextField(translate['Donations link'], 'donateUrl',
donateUrl, 'https://...') donateUrl, 'https://...')
editProfileForm += \ editProfileForm += \
_editText('Blog', 'blogAddress', blogAddress, 'https://...') editTextField('Blog', 'blogAddress', blogAddress, 'https://...')
languagesListStr = _getSupportedLanguages(baseDir) languagesListStr = _getSupportedLanguages(baseDir)
showLanguages = getActorLanguages(actorJson) showLanguages = getActorLanguages(actorJson)
editProfileForm += \ editProfileForm += \
_editText(translate['Languages'], 'showLanguages', editTextField(translate['Languages'], 'showLanguages',
showLanguages, languagesListStr) showLanguages, languagesListStr)
editProfileForm += ' </div>\n' editProfileForm += ' </div>\n'
@ -1837,7 +1786,7 @@ def _htmlEditProfileTopBanner(baseDir: str,
if scheduledPostsExist(baseDir, nickname, domain): if scheduledPostsExist(baseDir, nickname, domain):
editProfileForm += ' <div class="container">\n' editProfileForm += ' <div class="container">\n'
editProfileForm += \ editProfileForm += \
_editCheckBox(translate['Remove scheduled posts'], editCheckBox(translate['Remove scheduled posts'],
'removeScheduledPosts', False) 'removeScheduledPosts', False)
editProfileForm += ' </div>\n' editProfileForm += ' </div>\n'
return editProfileForm return editProfileForm

View File

@ -1111,3 +1111,61 @@ def htmlKeyboardNavigation(banner: str, links: {}, accessKeys: {},
str(title) + '</a></label></li>\n' str(title) + '</a></label></li>\n'
htmlStr += '</ul></div>\n' htmlStr += '</ul></div>\n'
return htmlStr return htmlStr
def beginEditSection(label: str) -> str:
"""returns the html for begining a dropdown section on edit profile screen
"""
return \
' <details><summary class="cw">' + label + '</summary>\n' + \
'<div class="container">'
def endEditSection() -> str:
"""returns the html for ending a dropdown section on edit profile screen
"""
return ' </div></details>\n'
def editTextField(label: str, name: str, value: str = "",
placeholder: str = "") -> str:
"""Returns html for editing a text field
"""
if value is None:
value = ''
placeholderStr = ''
if placeholder:
placeholderStr = ' placeholder="' + placeholder + '"'
return \
'<label class="labels">' + label + '</label><br>\n' + \
' <input type="text" name="' + name + '" value="' + \
value + '"' + placeholderStr + '>\n'
def editCheckBox(label: str, name: str, checked: bool = False) -> str:
"""Returns html for editing a checkbox field
"""
checkedStr = ''
if checked:
checkedStr = ' checked'
return \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="' + name + '"' + checkedStr + '> ' + label + '<br>\n'
def editTextArea(label: str, name: str, value: str = "",
height: int = 600,
placeholder: str = "",
spellcheck: bool = False) -> str:
"""Returns html for editing a textarea field
"""
if value is None:
value = ''
return \
'<label class="labels">' + label + '</label><br>\n' + \
' <textarea id="message" placeholder=' + \
'"' + placeholder + '" name="' + name + '" ' + \
'style="height:' + height + 'px" spellcheck="' + \
str(spellcheck).lower() + '">' + \
value + '</textarea>\n'

View File

@ -17,6 +17,7 @@ from utils import getImageFormats
from utils import acctDir from utils import acctDir
from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter from webapp_utils import htmlFooter
from webapp_utils import editTextField
from markdown import markdownToHtml from markdown import markdownToHtml
@ -102,10 +103,9 @@ def htmlWelcomeProfile(baseDir: str, nickname: str, domain: str,
actorJson = loadJson(actorFilename) actorJson = loadJson(actorFilename)
displayNickname = actorJson['name'] displayNickname = actorJson['name']
profileForm += '<div class="container">\n' profileForm += '<div class="container">\n'
profileForm += ' <label class="labels">' + \ profileForm += \
translate['Nickname'] + '</label><br>\n' editTextField(translate['Nickname'], 'displayNickname',
profileForm += ' <input type="text" name="displayNickname" value="' + \ displayNickname)
displayNickname + '"><br>\n'
bioStr = \ bioStr = \
actorJson['summary'].replace('<p>', '').replace('</p>', '') actorJson['summary'].replace('<p>', '').replace('</p>', '')