From 17e08b21366820f295df433a3b35c2764274a401 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 30 Oct 2021 12:51:41 +0100 Subject: [PATCH] Setting custom backgrounds --- webapp_calendar.py | 4 +--- webapp_confirm.py | 6 ++---- webapp_hashtagswarm.py | 7 +------ webapp_login.py | 6 +----- webapp_search.py | 14 ++------------ webapp_utils.py | 20 +++++++++++--------- 6 files changed, 18 insertions(+), 39 deletions(-) diff --git a/webapp_calendar.py b/webapp_calendar.py index 2fa9cdcb3..161cd63b1 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -51,8 +51,6 @@ def htmlCalendarDeleteConfirm(cssCache: {}, translate: {}, baseDir: str, if not postJsonObject: return None - setCustomBackground(baseDir, 'delete-background') - deletePostStr = None cssFilename = baseDir + '/epicyon-profile.css' if os.path.isfile(baseDir + '/epicyon.css'): @@ -284,7 +282,7 @@ def htmlCalendar(personCache: {}, cssCache: {}, translate: {}, nickname = getNicknameFromActor(actor) - setCustomBackground(baseDir, 'calendar-background') + setCustomBackground(baseDir, 'calendar-background', 'calendar-background') months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', diff --git a/webapp_confirm.py b/webapp_confirm.py index a483726cd..0d56fa1ac 100644 --- a/webapp_confirm.py +++ b/webapp_confirm.py @@ -55,8 +55,6 @@ def htmlConfirmDelete(cssCache: {}, if not postJsonObject: return None - setCustomBackground(baseDir, 'delete-background') - deletePostStr = None cssFilename = baseDir + '/epicyon-profile.css' if os.path.isfile(baseDir + '/epicyon.css'): @@ -132,7 +130,7 @@ def htmlConfirmRemoveSharedItem(cssCache: {}, translate: {}, baseDir: str, if sharesJson[itemID].get('imageUrl'): sharedItemImageUrl = sharesJson[itemID]['imageUrl'] - setCustomBackground(baseDir, 'shares-background') + setCustomBackground(baseDir, 'shares-background', 'follow-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): @@ -273,7 +271,7 @@ def htmlConfirmUnblock(cssCache: {}, translate: {}, baseDir: str, """ blockDomain, port = getDomainFromActor(blockActor) - setCustomBackground(baseDir, 'block-background') + setCustomBackground(baseDir, 'block-background', 'follow-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): diff --git a/webapp_hashtagswarm.py b/webapp_hashtagswarm.py index abf0996d5..6f4df63ed 100644 --- a/webapp_hashtagswarm.py +++ b/webapp_hashtagswarm.py @@ -201,7 +201,7 @@ def htmlSearchHashtagCategory(cssCache: {}, translate: {}, categoryStr = path.split('/category/')[1].strip() searchNickname = getNicknameFromActor(actor) - backgroundExt = setCustomBackground(baseDir, 'search-background') + setCustomBackground(baseDir, 'search-background', 'follow-background') cssFilename = baseDir + '/epicyon-search.css' if os.path.isfile(baseDir + '/search.css'): @@ -210,11 +210,6 @@ def htmlSearchHashtagCategory(cssCache: {}, translate: {}, instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') htmlStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) - if backgroundExt: - if backgroundExt != 'jpg': - htmlStr = htmlStr.replace('"follow-background.jpg"', - '"follow-background.' + - backgroundExt + '"') # show a banner above the search box searchBannerFile, searchBannerFilename = \ diff --git a/webapp_login.py b/webapp_login.py index 786112182..67d9bca3f 100644 --- a/webapp_login.py +++ b/webapp_login.py @@ -93,7 +93,7 @@ def htmlLogin(cssCache: {}, translate: {}, textModeLogo = getTextModeLogo(baseDir) textModeLogoHtml = htmlKeyboardNavigation(textModeLogo, {}, {}) - backgroundExt = setCustomBackground(baseDir, 'login-background-custom') + setCustomBackground(baseDir, 'login-background-custom', 'login-background') if accounts > 0: loginText = \ @@ -153,10 +153,6 @@ def htmlLogin(cssCache: {}, translate: {}, htmlHeaderWithWebsiteMarkup(cssFilename, instanceTitle, httpPrefix, domain, systemLanguage) - if backgroundExt: - loginForm = loginForm.replace('"login-background.jpg"', - '"login-background-custom.' + - backgroundExt + '"') nicknamePattern = getNicknameValidationPattern() instanceTitle = getConfigParam(baseDir, 'instanceTitle') diff --git a/webapp_search.py b/webapp_search.py index 94b820ec5..a6668c9b8 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -328,7 +328,7 @@ def htmlSearchEmojiTextEntry(cssCache: {}, translate: {}, actor = path.replace('/search', '') domain, port = getDomainFromActor(actor) - backgroundExt = setCustomBackground(baseDir, 'search-background') + setCustomBackground(baseDir, 'search-background', 'follow-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): @@ -337,11 +337,6 @@ def htmlSearchEmojiTextEntry(cssCache: {}, translate: {}, instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') emojiStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) - if backgroundExt: - if backgroundExt != 'jpg': - emojiStr = emojiStr.replace('"follow-background.jpg"', - '"follow-background.' + - backgroundExt + '"') emojiStr += '
\n' emojiStr += '
\n' emojiStr += '
\n' @@ -373,7 +368,7 @@ def htmlSearch(cssCache: {}, translate: {}, actor = path.replace('/search', '') searchNickname = getNicknameFromActor(actor) - backgroundExt = setCustomBackground(baseDir, 'search-background') + setCustomBackground(baseDir, 'search-background', 'follow-background') cssFilename = baseDir + '/epicyon-search.css' if os.path.isfile(baseDir + '/search.css'): @@ -381,11 +376,6 @@ def htmlSearch(cssCache: {}, translate: {}, instanceTitle = getConfigParam(baseDir, 'instanceTitle') followStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) - if backgroundExt: - if backgroundExt != 'jpg': - followStr = followStr.replace('"follow-background.jpg"', - '"follow-background.' + - backgroundExt + '"') # show a banner above the search box searchBannerFile, searchBannerFilename = \ diff --git a/webapp_utils.py b/webapp_utils.py index fa098e881..a03c4895b 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -1458,16 +1458,18 @@ def htmlShowShare(baseDir: str, domain: str, nickname: str, shareStr + htmlFooter() -def setCustomBackground(baseDir: str, background: str) -> str: +def setCustomBackground(baseDir: str, background: str, + newBackground: str) -> str: """Sets a custom background Returns the extension, if found """ - extensions = getImageExtensions() - for ext in extensions: - if os.path.isfile(baseDir + '/img/' + background + '.' + ext): - if not os.path.isfile(baseDir + '/accounts/' + - background + '.' + ext): - copyfile(baseDir + '/img/' + background + '.' + ext, - baseDir + '/accounts/' + background + '.' + ext) - return ext + ext = 'jpg' + if os.path.isfile(baseDir + '/img/' + background + '.' + ext): + if not newBackground: + newBackground = background + if not os.path.isfile(baseDir + '/accounts/' + + newBackground + '.' + ext): + copyfile(baseDir + '/img/' + background + '.' + ext, + baseDir + '/accounts/' + newBackground + '.' + ext) + return ext return None