Graphic design section on edit profile screen

main
Bob Mottram 2021-05-17 18:52:33 +01:00
parent 46687f8b6d
commit 7a78f8e7d8
19 changed files with 162 additions and 97 deletions

103
daemon.py
View File

@ -214,6 +214,7 @@ from utils import hasUsersPath
from utils import getFullDomain
from utils import removeHtml
from utils import isEditor
from utils import isArtist
from utils import getImageExtensions
from utils import mediaFileMimeType
from utils import getCSS
@ -4269,6 +4270,38 @@ class PubServer(BaseHTTPRequestHandler):
if checkNameAndBio:
redirectPath = 'previewAvatar'
if nickname == adminNickname or \
isArtist(baseDir, nickname):
# change theme
if fields.get('themeDropdown'):
self.server.themeName = fields['themeDropdown']
setTheme(baseDir, self.server.themeName, domain,
allowLocalNetworkAccess, systemLanguage)
self.server.textModeBanner = \
getTextModeBanner(self.server.baseDir)
self.server.iconsCache = {}
self.server.fontsCache = {}
self.server.showPublishAsIcon = \
getConfigParam(self.server.baseDir,
'showPublishAsIcon')
self.server.fullWidthTimelineButtonHeader = \
getConfigParam(self.server.baseDir,
'fullWidthTimelineButtonHeader')
self.server.iconsAsButtons = \
getConfigParam(self.server.baseDir,
'iconsAsButtons')
self.server.rssIconAtTop = \
getConfigParam(self.server.baseDir,
'rssIconAtTop')
self.server.publishButtonAtTop = \
getConfigParam(self.server.baseDir,
'publishButtonAtTop')
setNewsAvatar(baseDir,
fields['themeDropdown'],
httpPrefix,
domain,
domainFull)
if nickname == adminNickname:
# change media instance status
if fields.get('mediaInstance'):
@ -4353,36 +4386,6 @@ class PubServer(BaseHTTPRequestHandler):
"blogsInstance",
self.server.blogsInstance)
# change theme
if fields.get('themeDropdown'):
self.server.themeName = fields['themeDropdown']
setTheme(baseDir, self.server.themeName, domain,
allowLocalNetworkAccess, systemLanguage)
self.server.textModeBanner = \
getTextModeBanner(self.server.baseDir)
self.server.iconsCache = {}
self.server.fontsCache = {}
self.server.showPublishAsIcon = \
getConfigParam(self.server.baseDir,
'showPublishAsIcon')
self.server.fullWidthTimelineButtonHeader = \
getConfigParam(self.server.baseDir,
'fullWidthTimelineButtonHeader')
self.server.iconsAsButtons = \
getConfigParam(self.server.baseDir,
'iconsAsButtons')
self.server.rssIconAtTop = \
getConfigParam(self.server.baseDir,
'rssIconAtTop')
self.server.publishButtonAtTop = \
getConfigParam(self.server.baseDir,
'publishButtonAtTop')
setNewsAvatar(baseDir,
fields['themeDropdown'],
httpPrefix,
domain,
domainFull)
# change instance title
if fields.get('instanceTitle'):
currInstanceTitle = \
@ -4953,7 +4956,10 @@ class PubServer(BaseHTTPRequestHandler):
# remove a custom font
if fields.get('removeCustomFont'):
if fields['removeCustomFont'] == 'on':
if (fields['removeCustomFont'] == 'on' and
(isArtist(baseDir, nickname) or
path.startswith('/users/' +
adminNickname + '/'))):
fontExt = ('woff', 'woff2', 'otf', 'ttf')
for ext in fontExt:
if os.path.isfile(baseDir +
@ -4969,28 +4975,30 @@ class PubServer(BaseHTTPRequestHandler):
currTheme = getTheme(baseDir)
if currTheme:
self.server.themeName = currTheme
allowLocalNetworkAccess = \
self.server.allowLocalNetworkAccess
setTheme(baseDir, currTheme, domain,
self.server.allowLocalNetworkAccess,
allowLocalNetworkAccess,
systemLanguage)
self.server.textModeBanner = \
getTextModeBanner(self.server.baseDir)
getTextModeBanner(baseDir)
self.server.iconsCache = {}
self.server.fontsCache = {}
self.server.showPublishAsIcon = \
getConfigParam(self.server.baseDir,
getConfigParam(baseDir,
'showPublishAsIcon')
self.server.fullWidthTimelineButtonHeader = \
getConfigParam(self.server.baseDir,
getConfigParam(baseDir,
'fullWidthTimeline' +
'ButtonHeader')
self.server.iconsAsButtons = \
getConfigParam(self.server.baseDir,
getConfigParam(baseDir,
'iconsAsButtons')
self.server.rssIconAtTop = \
getConfigParam(self.server.baseDir,
getConfigParam(baseDir,
'rssIconAtTop')
self.server.publishButtonAtTop = \
getConfigParam(self.server.baseDir,
getConfigParam(baseDir,
'publishButtonAtTop')
# only receive DMs from accounts you follow
@ -5090,14 +5098,17 @@ class PubServer(BaseHTTPRequestHandler):
actorChanged = True
# grayscale theme
grayscale = False
if fields.get('grayscale'):
if fields['grayscale'] == 'on':
grayscale = True
if grayscale:
enableGrayscale(baseDir)
else:
disableGrayscale(baseDir)
if path.startswith('/users/' +
adminNickname + '/') or \
isArtist(baseDir, nickname):
grayscale = False
if fields.get('grayscale'):
if fields['grayscale'] == 'on':
grayscale = True
if grayscale:
enableGrayscale(baseDir)
else:
disableGrayscale(baseDir)
# save filtered words list
filterFilename = \

View File

@ -443,5 +443,6 @@
"Joined": "تاريخ الانضمام",
"City for spoofed GPS image metadata": "مدينة للبيانات الوصفية لصور GPS المخادعة",
"Occupation": "الاحتلال",
"Artists": "الفنانين"
"Artists": "الفنانين",
"Graphic Design": "التصميم الجرافيكي"
}

View File

@ -443,5 +443,6 @@
"Joined": "Data d'unió",
"City for spoofed GPS image metadata": "Ciutat per a metadades d'imatges GPS falsificades",
"Occupation": "Ocupació",
"Artists": "Artistes"
"Artists": "Artistes",
"Graphic Design": "Disseny gràfic"
}

View File

@ -443,5 +443,6 @@
"Joined": "Dyddiad ymuno",
"City for spoofed GPS image metadata": "Dinas ar gyfer metadata delwedd GPS spoofed",
"Occupation": "Ngalwedigaeth",
"Artists": "Artistiaid"
"Artists": "Artistiaid",
"Graphic Design": "Dylunio Graffig"
}

View File

@ -443,5 +443,6 @@
"Joined": "Verbundenes Datum",
"City for spoofed GPS image metadata": "Stadt für gefälschte GPS-Bildmetadaten",
"Occupation": "Besetzung",
"Artists": "Künstler"
"Artists": "Künstler",
"Graphic Design": "Grafikdesign"
}

View File

@ -443,5 +443,6 @@
"Joined": "Joined",
"City for spoofed GPS image metadata": "City for spoofed GPS image metadata",
"Occupation": "Occupation",
"Artists": "Artists"
"Artists": "Artists",
"Graphic Design": "Graphic Design"
}

View File

@ -443,5 +443,6 @@
"Joined": "Fecha unida",
"City for spoofed GPS image metadata": "Ciudad para metadatos de imagen GPS falsificados",
"Occupation": "Ocupación",
"Artists": "Artistas"
"Artists": "Artistas",
"Graphic Design": "Diseño gráfico"
}

View File

@ -443,5 +443,6 @@
"Joined": "Joint",
"City for spoofed GPS image metadata": "Ville pour les métadonnées d'image GPS falsifiées",
"Occupation": "Occupation",
"Artists": "Artistes"
"Artists": "Artistes",
"Graphic Design": "Conception graphique"
}

View File

@ -443,5 +443,6 @@
"Joined": "Dáta comhcheangailte",
"City for spoofed GPS image metadata": "Cathair le haghaidh meiteashonraí íomhá GPS spoofed",
"Occupation": "Slí bheatha",
"Artists": "Ealaíontóirí"
"Artists": "Ealaíontóirí",
"Graphic Design": "Dearadh grafach"
}

View File

@ -443,5 +443,6 @@
"Joined": "दिनांक",
"City for spoofed GPS image metadata": "स्पूफ जीपीएस जीपीएस मेटाडेटा के लिए शहर",
"Occupation": "व्यवसाय",
"Artists": "कलाकार की"
"Artists": "कलाकार की",
"Graphic Design": "ग्राफ़िक डिज़ाइन"
}

View File

@ -443,5 +443,6 @@
"Joined": "Unito",
"City for spoofed GPS image metadata": "Città per metadati di immagini GPS falsificate",
"Occupation": "Occupazione",
"Artists": "Artiste"
"Artists": "Artiste",
"Graphic Design": "Graphic design"
}

View File

@ -443,5 +443,6 @@
"Joined": "参加日",
"City for spoofed GPS image metadata": "なりすましGPS画像メタデータの都市",
"Occupation": "職業",
"Artists": "アーティスト"
"Artists": "アーティスト",
"Graphic Design": "グラフィックデザイン"
}

View File

@ -443,5 +443,6 @@
"Joined": "Beşdarbûna Dîrokê",
"City for spoofed GPS image metadata": "Bajar ji bo metadata wêneya GPS ya xapînok",
"Occupation": "Sinet",
"Artists": "Hunermend"
"Artists": "Hunermend",
"Graphic Design": "Sêwirana grafîkî"
}

View File

@ -439,5 +439,6 @@
"Joined": "Joined",
"City for spoofed GPS image metadata": "City for spoofed GPS image metadata",
"Occupation": "Occupation",
"Artists": "Artists"
"Artists": "Artists",
"Graphic Design": "Graphic Design"
}

View File

@ -443,5 +443,6 @@
"Joined": "Data juntada",
"City for spoofed GPS image metadata": "Cidade para metadados de imagem GPS falsificados",
"Occupation": "Ocupação",
"Artists": "Artistas"
"Artists": "Artistas",
"Graphic Design": "Design gráfico"
}

View File

@ -443,5 +443,6 @@
"Joined": "Присоединенная дата",
"City for spoofed GPS image metadata": "Город для поддельных метаданных изображения GPS",
"Occupation": "Занятие",
"Artists": "Художники"
"Artists": "Художники",
"Graphic Design": "Графический дизайн"
}

View File

@ -443,5 +443,6 @@
"Joined": "加入日期",
"City for spoofed GPS image metadata": "欺骗性GPS影像元数据的城市",
"Occupation": "职业",
"Artists": "艺人"
"Artists": "艺人",
"Graphic Design": "平面设计"
}

View File

@ -194,6 +194,34 @@ def isEditor(baseDir: str, nickname: str) -> bool:
return False
def isArtist(baseDir: str, nickname: str) -> bool:
"""Returns true if the given nickname is an artist
"""
artistsFile = baseDir + '/accounts/artists.txt'
if not os.path.isfile(artistsFile):
adminName = getConfigParam(baseDir, 'admin')
if not adminName:
return False
if adminName == nickname:
return True
return False
with open(artistsFile, "r") as f:
lines = f.readlines()
if len(lines) == 0:
adminName = getConfigParam(baseDir, 'admin')
if not adminName:
return False
if adminName == nickname:
return True
for artist in lines:
artist = artist.strip('\n').strip('\r')
if artist == nickname:
return True
return False
def getImageExtensions() -> []:
"""Returns a list of the possible image file extensions
"""

View File

@ -12,6 +12,7 @@ from utils import getOccupationName
from utils import getLockedAccount
from utils import hasUsersPath
from utils import getFullDomain
from utils import isArtist
from utils import isDormant
from utils import getNicknameFromActor
from utils import getDomainFromActor
@ -1292,6 +1293,49 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
peertubeStr = ''
adminNickname = getConfigParam(baseDir, 'admin')
if isArtist(baseDir, nickname) or \
path.startswith('/users/' + str(adminNickname) + '/'):
graphicsStr = '<details><summary class="cw">' + \
translate['Graphic Design'] + '</summary>\n'
graphicsStr += '<div class="container">'
# Themes section
themes = getThemesList(baseDir)
themesDropdown += ' <br><label class="labels">' + \
translate['Theme'] + '</label><br>\n'
grayscaleFilename = \
baseDir + '/accounts/.grayscale'
grayscale = ''
if os.path.isfile(grayscaleFilename):
grayscale = 'checked'
themesDropdown += \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="grayscale" ' + grayscale + \
'> ' + translate['Grayscale'] + '<br>'
themesDropdown += ' <select id="themeDropdown" ' + \
'name="themeDropdown" class="theme">'
for themeName in themes:
themesDropdown += ' <option value="' + \
themeName.lower() + '">' + \
translate[themeName] + '</option>'
themesDropdown += ' </select><br>'
if os.path.isfile(baseDir + '/fonts/custom.woff') or \
os.path.isfile(baseDir + '/fonts/custom.woff2') or \
os.path.isfile(baseDir + '/fonts/custom.otf') or \
os.path.isfile(baseDir + '/fonts/custom.ttf'):
themesDropdown += \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="removeCustomFont"> ' + \
translate['Remove the custom font'] + '<br>'
themeName = getConfigParam(baseDir, 'theme')
themesDropdown = \
themesDropdown.replace('<option value="' + themeName + '">',
'<option value="' + themeName +
'" selected>')
graphicsStr += themesDropdown
graphicsStr += ' </div></details>\n'
if adminNickname:
if path.startswith('/users/' + adminNickname + '/'):
# Instance details section
@ -1346,40 +1390,6 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
' <input type="file" id="instanceLogo" name="instanceLogo"'
instanceStr += ' accept="' + imageFormats + '"><br>\n'
# Themes section
themes = getThemesList(baseDir)
themesDropdown += ' <br><label class="labels">' + \
translate['Theme'] + '</label><br>\n'
grayscaleFilename = \
baseDir + '/accounts/.grayscale'
grayscale = ''
if os.path.isfile(grayscaleFilename):
grayscale = 'checked'
themesDropdown += \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="grayscale" ' + grayscale + \
'> ' + translate['Grayscale'] + '<br>'
themesDropdown += ' <select id="themeDropdown" ' + \
'name="themeDropdown" class="theme">'
for themeName in themes:
themesDropdown += ' <option value="' + \
themeName.lower() + '">' + \
translate[themeName] + '</option>'
themesDropdown += ' </select><br>'
if os.path.isfile(baseDir + '/fonts/custom.woff') or \
os.path.isfile(baseDir + '/fonts/custom.woff2') or \
os.path.isfile(baseDir + '/fonts/custom.otf') or \
os.path.isfile(baseDir + '/fonts/custom.ttf'):
themesDropdown += \
' <input type="checkbox" class="profilecheckbox" ' + \
'name="removeCustomFont"> ' + \
translate['Remove the custom font'] + '<br>'
themeName = getConfigParam(baseDir, 'theme')
themesDropdown = \
themesDropdown.replace('<option value="' + themeName + '">',
'<option value="' + themeName +
'" selected>')
instanceStr += themesDropdown
instanceStr += \
' <br><label class="labels">' + \
translate['Security'] + '</label><br>\n'
@ -1942,7 +1952,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
editProfileForm += ' <label class="labels">' + \
translate[idx] + '</label>\n'
editProfileForm += skillsStr
editProfileForm += roleAssignStr + peertubeStr + instanceStr
editProfileForm += roleAssignStr + peertubeStr + graphicsStr + instanceStr
# danger zone section
editProfileForm += ' <details><summary class="cw">' + \