Function for filtering section of edit profile screen

merge-requests/30/head
Bob Mottram 2021-06-27 20:44:57 +01:00
parent aaa71b542e
commit 6a8148d703
1 changed files with 173 additions and 164 deletions

View File

@ -1413,6 +1413,178 @@ def _htmlEditProfileGitProjects(baseDir: str, nickname: str, domain: str,
return editProfileForm
def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str,
translate: {}) -> str:
"""Filtering and blocking section of edit profile screen
"""
filterStr = ''
filterFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + '/filters.txt'
if os.path.isfile(filterFilename):
with open(filterFilename, 'r') as filterfile:
filterStr = filterfile.read()
switchStr = ''
switchFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/replacewords.txt'
if os.path.isfile(switchFilename):
with open(switchFilename, 'r') as switchfile:
switchStr = switchfile.read()
autoTags = ''
autoTagsFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autotags.txt'
if os.path.isfile(autoTagsFilename):
with open(autoTagsFilename, 'r') as autoTagsFile:
autoTags = autoTagsFile.read()
autoCW = ''
autoCWFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autocw.txt'
if os.path.isfile(autoCWFilename):
with open(autoCWFilename, 'r') as autoCWFile:
autoCW = autoCWFile.read()
blockedStr = ''
blockedFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/blocking.txt'
if os.path.isfile(blockedFilename):
with open(blockedFilename, 'r') as blockedfile:
blockedStr = blockedfile.read()
dmAllowedInstancesStr = ''
dmAllowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/dmAllowedInstances.txt'
if os.path.isfile(dmAllowedInstancesFilename):
with open(dmAllowedInstancesFilename, 'r') as dmAllowedInstancesFile:
dmAllowedInstancesStr = dmAllowedInstancesFile.read()
allowedInstancesStr = ''
allowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/allowedinstances.txt'
if os.path.isfile(allowedInstancesFilename):
with open(allowedInstancesFilename, 'r') as allowedInstancesFile:
allowedInstancesStr = allowedInstancesFile.read()
editProfileForm = '<details><summary class="cw">' + \
translate['Filtering and Blocking'] + '</summary>\n'
editProfileForm += ' <div class="container">\n'
editProfileForm += \
'<label class="labels">' + \
translate['City for spoofed GPS image metadata'] + \
'</label><br>\n'
cityFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/city.txt'
if os.path.isfile(cityFilename):
with open(cityFilename, 'r') as fp:
city = fp.read().replace('\n', '')
locationsFilename = baseDir + '/custom_locations.txt'
if not os.path.isfile(locationsFilename):
locationsFilename = baseDir + '/locations.txt'
cities = []
with open(locationsFilename, "r") as f:
cities = f.readlines()
cities.sort()
editProfileForm += ' <select id="cityDropdown" ' + \
'name="cityDropdown" class="theme">\n'
city = city.lower()
for cityName in cities:
if ':' not in cityName:
continue
citySelected = ''
cityName = cityName.split(':')[0]
cityName = cityName.lower()
if city in cityName:
citySelected = ' selected'
editProfileForm += \
' <option value="' + cityName + \
'"' + citySelected.title() + '>' + \
cityName + '</option>\n'
editProfileForm += ' </select><br>\n'
editProfileForm += \
' <b><label class="labels">' + \
translate['Filtered words'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">' + \
translate['One per line'] + '</label>\n'
editProfileForm += ' <textarea id="message" ' + \
'name="filteredWords" style="height:200px" spellcheck="false">' + \
filterStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Word Replacements'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">A -> B</label>\n'
editProfileForm += \
' <textarea id="message" name="switchWords" ' + \
'style="height:200px" spellcheck="false">' + \
switchStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Autogenerated Hashtags'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">A -> #B</label>\n'
editProfileForm += \
' <textarea id="message" name="autoTags" ' + \
'style="height:200px" spellcheck="false">' + \
autoTags + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Autogenerated Content Warnings'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">A -> B</label>\n'
editProfileForm += \
' <textarea id="message" name="autoCW" ' + \
'style="height:200px" spellcheck="true">' + autoCW + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Blocked accounts'] + '</label></b>\n'
idx = 'Blocked accounts, one per line, in the form ' + \
'nickname@domain or *@blockeddomain'
editProfileForm += \
' <br><label class="labels">' + translate[idx] + '</label>\n'
editProfileForm += \
' <textarea id="message" name="blocked" style="height:200px" ' + \
'spellcheck="false">' + blockedStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Direct Message permitted instances'] + '</label></b>\n'
idx = 'Direct messages are always allowed from these instances.'
editProfileForm += \
' <br><label class="labels">' + \
translate[idx] + '</label>\n'
editProfileForm += \
' <textarea id="message" name="dmAllowedInstances" ' + \
'style="height:200px" spellcheck="false">' + \
dmAllowedInstancesStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Federation list'] + '</label></b>\n'
idx = 'Federate only with a defined set of instances. ' + \
'One domain name per line.'
editProfileForm += \
' <br><label class="labels">' + \
translate[idx] + '</label>\n'
editProfileForm += \
' <textarea id="message" name="allowedInstances" ' + \
'style="height:200px" spellcheck="false">' + \
allowedInstancesStr + '</textarea>\n'
editProfileForm += ' </div></details>\n'
return editProfileForm
def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
domain: str, port: int, httpPrefix: str,
defaultTimeline: str, theme: str,
@ -1514,61 +1686,6 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
blogsInstanceStr = 'checked'
mediaInstanceStr = newsInstanceStr = ''
filterStr = ''
filterFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + '/filters.txt'
if os.path.isfile(filterFilename):
with open(filterFilename, 'r') as filterfile:
filterStr = filterfile.read()
switchStr = ''
switchFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/replacewords.txt'
if os.path.isfile(switchFilename):
with open(switchFilename, 'r') as switchfile:
switchStr = switchfile.read()
autoTags = ''
autoTagsFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autotags.txt'
if os.path.isfile(autoTagsFilename):
with open(autoTagsFilename, 'r') as autoTagsFile:
autoTags = autoTagsFile.read()
autoCW = ''
autoCWFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autocw.txt'
if os.path.isfile(autoCWFilename):
with open(autoCWFilename, 'r') as autoCWFile:
autoCW = autoCWFile.read()
blockedStr = ''
blockedFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/blocking.txt'
if os.path.isfile(blockedFilename):
with open(blockedFilename, 'r') as blockedfile:
blockedStr = blockedfile.read()
dmAllowedInstancesStr = ''
dmAllowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/dmAllowedInstances.txt'
if os.path.isfile(dmAllowedInstancesFilename):
with open(dmAllowedInstancesFilename, 'r') as dmAllowedInstancesFile:
dmAllowedInstancesStr = dmAllowedInstancesFile.read()
allowedInstancesStr = ''
allowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/allowedinstances.txt'
if os.path.isfile(allowedInstancesFilename):
with open(allowedInstancesFilename, 'r') as allowedInstancesFile:
allowedInstancesStr = allowedInstancesFile.read()
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
@ -1858,116 +1975,8 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
editProfileForm += ' </div></details>\n'
# Filtering and blocking section
editProfileForm += '<details><summary class="cw">' + \
translate['Filtering and Blocking'] + '</summary>\n'
editProfileForm += ' <div class="container">\n'
editProfileForm += \
'<label class="labels">' + \
translate['City for spoofed GPS image metadata'] + \
'</label><br>\n'
cityFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/city.txt'
if os.path.isfile(cityFilename):
with open(cityFilename, 'r') as fp:
city = fp.read().replace('\n', '')
locationsFilename = baseDir + '/custom_locations.txt'
if not os.path.isfile(locationsFilename):
locationsFilename = baseDir + '/locations.txt'
cities = []
with open(locationsFilename, "r") as f:
cities = f.readlines()
cities.sort()
editProfileForm += ' <select id="cityDropdown" ' + \
'name="cityDropdown" class="theme">\n'
city = city.lower()
for cityName in cities:
if ':' not in cityName:
continue
citySelected = ''
cityName = cityName.split(':')[0]
cityName = cityName.lower()
if city in cityName:
citySelected = ' selected'
editProfileForm += \
' <option value="' + cityName + \
'"' + citySelected.title() + '>' + \
cityName + '</option>\n'
editProfileForm += ' </select><br>\n'
editProfileForm += \
' <b><label class="labels">' + \
translate['Filtered words'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">' + \
translate['One per line'] + '</label>\n'
editProfileForm += ' <textarea id="message" ' + \
'name="filteredWords" style="height:200px" spellcheck="false">' + \
filterStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Word Replacements'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">A -> B</label>\n'
editProfileForm += \
' <textarea id="message" name="switchWords" ' + \
'style="height:200px" spellcheck="false">' + \
switchStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Autogenerated Hashtags'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">A -> #B</label>\n'
editProfileForm += \
' <textarea id="message" name="autoTags" ' + \
'style="height:200px" spellcheck="false">' + \
autoTags + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Autogenerated Content Warnings'] + '</label></b>\n'
editProfileForm += ' <br><label class="labels">A -> B</label>\n'
editProfileForm += \
' <textarea id="message" name="autoCW" ' + \
'style="height:200px" spellcheck="true">' + autoCW + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Blocked accounts'] + '</label></b>\n'
idx = 'Blocked accounts, one per line, in the form ' + \
'nickname@domain or *@blockeddomain'
editProfileForm += \
' <br><label class="labels">' + translate[idx] + '</label>\n'
editProfileForm += \
' <textarea id="message" name="blocked" style="height:200px" ' + \
'spellcheck="false">' + blockedStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Direct Message permitted instances'] + '</label></b>\n'
idx = 'Direct messages are always allowed from these instances.'
editProfileForm += \
' <br><label class="labels">' + \
translate[idx] + '</label>\n'
editProfileForm += \
' <textarea id="message" name="dmAllowedInstances" ' + \
'style="height:200px" spellcheck="false">' + \
dmAllowedInstancesStr + '</textarea>\n'
editProfileForm += \
' <br><b><label class="labels">' + \
translate['Federation list'] + '</label></b>\n'
idx = 'Federate only with a defined set of instances. ' + \
'One domain name per line.'
editProfileForm += \
' <br><label class="labels">' + \
translate[idx] + '</label>\n'
editProfileForm += \
' <textarea id="message" name="allowedInstances" ' + \
'style="height:200px" spellcheck="false">' + \
allowedInstancesStr + '</textarea>\n'
editProfileForm += ' </div></details>\n'
_htmlEditProfileFiltering(baseDir, nickname, domain, translate)
# git projects section
editProfileForm += \