Tidying of profile edit fields

merge-requests/30/head
Bob Mottram 2021-07-22 13:36:31 +01:00
parent c50d30393c
commit 1d11b177d8
1 changed files with 102 additions and 141 deletions

View File

@ -60,21 +60,51 @@ 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 = "") -> str: def _editText(label: str, name: str, value: str = "") -> str:
"""Returns html for editing a text field """Returns html for editing a text field
""" """
if value is None:
value = ''
return \ return \
'<label class="labels">' + label + '</label><br>\n' + \ '<label class="labels">' + label + '</label><br>\n' + \
' <input type="text" name="' + name + '" value="' + \ ' <input type="text" name="' + name + '" value="' + \
value + '">\n' value + '">\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 = "", def _editTextArea(label: str, name: str, value: str = "",
height: int = 600, height: int = 600,
placeholder: str = "", placeholder: str = "",
spellcheck: bool = False) -> str: spellcheck: bool = False) -> str:
"""Returns html for editing a textarea field """Returns html for editing a textarea field
""" """
if value is None:
value = ''
return \ return \
'<label class="labels">' + label + '</label><br>\n' + \ '<label class="labels">' + label + '</label><br>\n' + \
' <textarea id="message" placeholder=' + \ ' <textarea id="message" placeholder=' + \
@ -1049,13 +1079,9 @@ def _htmlThemesDropdown(baseDir: str, translate: {}) -> str:
themes = getThemesList(baseDir) themes = getThemesList(baseDir)
themesDropdown = ' <label class="labels">' + \ themesDropdown = ' <label class="labels">' + \
translate['Theme'] + '</label><br>\n' translate['Theme'] + '</label><br>\n'
grayscale = '' grayscale = _grayscaleEnabled(baseDir)
if _grayscaleEnabled(baseDir):
grayscale = 'checked'
themesDropdown += \ themesDropdown += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Grayscale'], 'grayscale', grayscale)
'name="grayscale" ' + grayscale + \
'> ' + translate['Grayscale'] + '<br>'
themesDropdown += ' <select id="themeDropdown" ' + \ themesDropdown += ' <select id="themeDropdown" ' + \
'name="themeDropdown" class="theme">' 'name="themeDropdown" class="theme">'
for themeName in themes: for themeName in themes:
@ -1071,9 +1097,8 @@ 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 += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Remove the custom font'],
'name="removeCustomFont"> ' + \ 'removeCustomFont', False)
translate['Remove the custom font'] + '<br>'
themeName = getConfigParam(baseDir, 'theme') themeName = getConfigParam(baseDir, 'theme')
themesDropdown = \ themesDropdown = \
themesDropdown.replace('<option value="' + themeName + '">', themesDropdown.replace('<option value="' + themeName + '">',
@ -1127,57 +1152,24 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
instanceTitle = \ instanceTitle = \
getConfigParam(baseDir, 'instanceTitle') getConfigParam(baseDir, 'instanceTitle')
instanceStr = '<details><summary class="cw">' + \ instanceStr = _beginEditSection(translate['Instance Settings'])
translate['Instance Settings'] + '</summary>\n'
instanceStr += '<div class="container">'
instanceStr += \
' <label class="labels">' + \
translate['Instance Title'] + '</label>'
if instanceTitle:
instanceStr += \
' <input type="text" name="instanceTitle" value="' + \
instanceTitle + '"><br>'
else:
instanceStr += \
' <input type="text" name="instanceTitle" value=""><br>'
instanceStr += \
' <label class="labels">' + \
translate['Instance Short Description'] + '</label>'
if instanceDescriptionShort:
instanceStr += \
' <input type="text" ' + \
'name="instanceDescriptionShort" value="' + \
instanceDescriptionShort + '"><br>'
else:
instanceStr += \
' <input type="text" ' + \
'name="instanceDescriptionShort" value=""><br>'
instanceStr += \
' <label class="labels">' + \
translate['Instance Description'] + '</label>'
if instanceDescription:
instanceStr += \
' <textarea id="message" name="instanceDescription" ' + \
'style="height:200px" spellcheck="true">' + \
instanceDescription + '</textarea>'
else:
instanceStr += \
' <textarea id="message" name="instanceDescription" ' + \
'style="height:200px" spellcheck="true"></textarea>'
instanceStr += \ instanceStr += \
' <label class="labels">' + \ _editText(translate['Instance Title'],
translate['Custom post submit button text'] + '</label>' 'instanceTitle', instanceTitle)
if customSubmitText: instanceStr += '<br>\n'
instanceStr += \ instanceStr += \
' <input type="text" ' + \ _editText(translate['Instance Short Description'],
'name="customSubmitText" value="' + \ 'instanceDescriptionShort', instanceDescriptionShort)
customSubmitText + '"><br>' instanceStr += '<br>\n'
else: instanceStr += \
instanceStr += \ _editTextArea(translate['Instance Description'],
' <input type="text" ' + \ 'instanceDescription', instanceDescription, 200,
'name="customSubmitText" value=""><br>' '', True)
instanceStr += \
_editText(translate['Custom post submit button text'],
'customSubmitText', customSubmitText)
instanceStr += '<br>\n'
instanceStr += \ instanceStr += \
' <label class="labels">' + \ ' <label class="labels">' + \
translate['Instance Logo'] + '</label>' + \ translate['Instance Logo'] + '</label>' + \
@ -1190,64 +1182,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 += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(nodeInfoStr, 'showNodeInfoAccounts', True)
'name="showNodeInfoAccounts" checked> ' + \
nodeInfoStr + '<br>\n'
else: else:
instanceStr += \ instanceStr += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(nodeInfoStr, 'showNodeInfoAccounts', False)
'name="showNodeInfoAccounts"> ' + \
nodeInfoStr + '<br>\n'
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 += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(nodeInfoStr, 'showNodeInfoVersion', True)
'name="showNodeInfoVersion" checked> ' + \
nodeInfoStr + '<br>\n'
else: else:
instanceStr += \ instanceStr += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(nodeInfoStr, 'showNodeInfoVersion', False)
'name="showNodeInfoVersion"> ' + \
nodeInfoStr + '<br>\n'
if getConfigParam(baseDir, "verifyAllSignatures"): if getConfigParam(baseDir, "verifyAllSignatures"):
instanceStr += \ instanceStr += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Verify all signatures'],
'name="verifyallsignatures" checked> ' + \ 'verifyallsignatures', True)
translate['Verify all signatures'] + '<br>\n'
else: else:
instanceStr += \ instanceStr += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Verify all signatures'],
'name="verifyallsignatures"> ' + \ 'verifyallsignatures', False)
translate['Verify all signatures'] + '<br>\n'
instanceStr += translate['Enabling broch mode'] + '<br>\n' instanceStr += translate['Enabling broch mode'] + '<br>\n'
if getConfigParam(baseDir, "brochMode"): if getConfigParam(baseDir, "brochMode"):
instanceStr += \ instanceStr += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Broch mode'], 'brochMode', True)
'name="brochMode" checked> ' + \
translate['Broch mode'] + '<br>\n'
else: else:
instanceStr += \ instanceStr += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Broch mode'], 'brochMode', False)
'name="brochMode"> ' + \
translate['Broch mode'] + '<br>\n'
# 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'
' <input type="checkbox" class="profilecheckbox" ' + \ instanceStr += \
'name="mediaInstance" ' + mediaInstanceStr + '> ' + \ _editCheckBox(translate['This is a media instance'],
translate['This is a media instance'] + '<br>\n' + \ 'mediaInstance', mediaInstanceStr)
' <input type="checkbox" class="profilecheckbox" ' + \ instanceStr += \
'name="blogsInstance" ' + blogsInstanceStr + '> ' + \ _editCheckBox(translate['This is a blogging instance'],
translate['This is a blogging instance'] + '<br>\n' + \ 'blogsInstance', blogsInstanceStr)
' <input type="checkbox" class="profilecheckbox" ' + \ instanceStr += \
'name="newsInstance" ' + newsInstanceStr + '> ' + \ _editCheckBox(translate['This is a news instance'],
translate['This is a news instance'] + '<br>\n' + \ 'newsInstance', newsInstanceStr)
' </div></details>\n'
instanceStr += _endEditSection()
# Role assignments section # Role assignments section
moderators = '' moderators = ''
@ -1330,15 +1309,14 @@ def _htmlEditProfileInstance(baseDir: str, translate: {},
' <textarea id="message" name="ptInstances" ' + \ ' <textarea id="message" name="ptInstances" ' + \
'style="height:200px" spellcheck="false">' + \ 'style="height:200px" spellcheck="false">' + \
peertubeInstancesStr + '</textarea>\n' + \ peertubeInstancesStr + '</textarea>\n' + \
' <br><b><label class="labels">' + \ ' <br>\n'
translate['YouTube Replacement Domain'] + '</label></b>\n'
YTReplacementDomain = getConfigParam(baseDir, "youtubedomain") YTReplacementDomain = getConfigParam(baseDir, "youtubedomain")
if not YTReplacementDomain: if not YTReplacementDomain:
YTReplacementDomain = '' YTReplacementDomain = ''
peertubeStr += \ peertubeStr += \
' <input type="text" name="ytdomain" value="' + \ _editText(translate['YouTube Replacement Domain'],
YTReplacementDomain + '">\n' + \ 'ytdomain', YTReplacementDomain)
' </div></details>\n' peertubeStr += _endEditSection()
libretranslateUrl = getConfigParam(baseDir, 'libretranslateUrl') libretranslateUrl = getConfigParam(baseDir, 'libretranslateUrl')
libretranslateApiKey = getConfigParam(baseDir, 'libretranslateApiKey') libretranslateApiKey = getConfigParam(baseDir, 'libretranslateApiKey')
@ -1356,12 +1334,17 @@ def _htmlEditProfileDangerZone(translate: {}) -> str:
editProfileForm = \ editProfileForm = \
' <details><summary class="cw">' + \ ' <details><summary class="cw">' + \
translate['Danger Zone'] + '</summary>\n' + \ translate['Danger Zone'] + '</summary>\n' + \
' <div class="container">\n' + \ ' <div class="container">\n'
editProfileForm = \
' <b><label class="labels">' + \ ' <b><label class="labels">' + \
translate['Danger Zone'] + '</label></b><br>\n' + \ translate['Danger Zone'] + '</label></b><br>\n'
' <input type="checkbox" class=dangercheckbox" ' + \
'name="deactivateThisAccount"> ' + \ editProfileForm = \
translate['Deactivate this account'] + '<br>\n' + \ _editCheckBox(translate['Deactivate this account'],
'deactivateThisAccount', False)
editProfileForm = \
' </div></details>\n' ' </div></details>\n'
return editProfileForm return editProfileForm
@ -1683,20 +1666,6 @@ def _htmlEditProfileBackground(newsInstance: bool, translate: {}) -> str:
return editProfileForm return editProfileForm
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 _htmlEditProfileContactInfo(nickname: str, def _htmlEditProfileContactInfo(nickname: str,
emailAddress: str, emailAddress: str,
xmppAddress: str, xmppAddress: str,
@ -1747,33 +1716,26 @@ def _htmlEditProfileOptions(manuallyApprovesFollowers: str,
""" """
editProfileForm = ' <div class="container">\n' editProfileForm = ' <div class="container">\n'
editProfileForm += \ editProfileForm += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Approve follower requests'],
'name="approveFollowers" ' + manuallyApprovesFollowers + \ 'approveFollowers', manuallyApprovesFollowers)
'> ' + translate['Approve follower requests'] + '<br>\n'
editProfileForm += \ editProfileForm += \
' <input type="checkbox" ' + \ _editCheckBox(translate['This is a bot account'],
'class="profilecheckbox" name="isBot" ' + \ 'isBot', isBot)
isBot + '> ' + translate['This is a bot account'] + '<br>\n'
editProfileForm += \ editProfileForm += \
' <input type="checkbox" ' + \ _editCheckBox(translate['This is a group account'],
'class="profilecheckbox" name="isGroup" ' + isGroup + '> ' + \ 'isGroup', isGroup)
translate['This is a group account'] + '<br>\n'
editProfileForm += \ editProfileForm += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Only people I follow can send me DMs'],
'name="followDMs" ' + followDMs + '> ' + \ 'followDMs', followDMs)
translate['Only people I follow can send me DMs'] + '<br>\n'
editProfileForm += \ editProfileForm += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Remove Twitter posts'],
'name="removeTwitter" ' + removeTwitter + '> ' + \ 'removeTwitter', removeTwitter)
translate['Remove Twitter posts'] + '<br>\n'
editProfileForm += \ editProfileForm += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Notify when posts are liked'],
'name="notifyLikes" ' + notifyLikes + '> ' + \ 'notifyLikes', notifyLikes)
translate['Notify when posts are liked'] + '<br>\n'
editProfileForm += \ editProfileForm += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate["Don't show the Like button"],
'name="hideLikeButton" ' + hideLikeButton + '> ' + \ 'hideLikeButton', hideLikeButton)
translate["Don't show the Like button"] + '<br>\n'
editProfileForm += ' </div>\n' editProfileForm += ' </div>\n'
return editProfileForm return editProfileForm
@ -1917,9 +1879,8 @@ 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 += \
' <input type="checkbox" class="profilecheckbox" ' + \ _editCheckBox(translate['Remove scheduled posts'],
'name="removeScheduledPosts"> ' + \ 'removeScheduledPosts', False)
translate['Remove scheduled posts'] + '<br>\n'
editProfileForm += ' </div>\n' editProfileForm += ' </div>\n'
return editProfileForm return editProfileForm