From 7d60cdacb20339bb154b720500d4526600e9f3bb Mon Sep 17 00:00:00 2001 From: OMN Date: Sat, 12 Dec 2020 19:38:38 +0000 Subject: [PATCH] Quick fixes - Usage of headerNewsTabs() - Remove 'Login' button from newswire column - Display front page correctly when not logged in - Add multi/themed CSS to front page and edit profile page - Show site banner on profile edit page - Include edit profile in "user pages" list --- webapp_column_left.py | 2 +- webapp_column_right.py | 18 ++++---- webapp_create_post.py | 7 ++- webapp_frontscreen.py | 102 ++++++++++++++++++++++++++--------------- webapp_profile.py | 85 ++++++++++++++++++++++++++++++---- webapp_timeline.py | 7 +-- 6 files changed, 158 insertions(+), 63 deletions(-) diff --git a/webapp_column_left.py b/webapp_column_left.py index f4a9dcb1..ab92f0bf 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -306,7 +306,7 @@ def htmlLinksMobile(cssCache: {}, baseDir: str, # Full row "navbar" if defaultTimeline == 'tlfeatures': # Show "tab" links instead of standard "buttons" - htmlStr += headerNewsTabs('linksmobile', translate, usersPath, baseDir, userPages) + htmlStr += headerNewsTabs('linksmobile', translate, usersPath, baseDir, authorized, userPages) # Close banner div htmlStr += '\n' diff --git a/webapp_column_right.py b/webapp_column_right.py index 5effe409..41a32858 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -61,6 +61,7 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str, if ':' in domain: domain = domain.split(':') + publishButtonStr = None if authorized: # only show the publish button if logged in, otherwise replace it with # a login button @@ -70,15 +71,16 @@ def getRightColumnContent(baseDir: str, nickname: str, domainFull: str, 'title="' + translate['Publish a news article'] + '">' + \ '\n' - else: - # if not logged in then replace the publish button with - # a login button - publishButtonStr = \ - ' \n' +# NOTE: Removed from this fork as is handled by 'htmlFooter' in webapp_utils.py +# else: +# # if not logged in then replace the publish button with +# # a login button +# publishButtonStr = \ +# ' \n' # show publish button at the top if needed - if publishButtonAtTop: + if publishButtonStr and publishButtonAtTop: htmlStr += '
' + publishButtonStr + '
' editImageClass = '' @@ -477,7 +479,7 @@ def htmlNewswireMobile(cssCache: {}, baseDir: str, nickname: str, # Full row "navbar" if defaultTimeline == 'tlfeatures': # Show "tab" links instead of standard "buttons" - htmlStr += headerNewsTabs('newswiremobile', translate, usersPath, baseDir, userPages) + htmlStr += headerNewsTabs('newswiremobile', translate, usersPath, baseDir, authorized, userPages) # Close banner div htmlStr += '\n' diff --git a/webapp_create_post.py b/webapp_create_post.py index da0be76a..36ddd295 100644 --- a/webapp_create_post.py +++ b/webapp_create_post.py @@ -599,7 +599,10 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {}, if defaultTimeline == 'tlfeatures': # Show "tab" links instead of standard "buttons" # NOTE: "inbox" is used as a generic boxName, as with 'User' pages - newPostForm += headerNewsTabs('inbox', translate, usersPath, baseDir, userPages) + # NOTE: It should be "safe" to assume that this code would not be running, + # unless the user was already deemed 'authorized', + # thus allowing us to pass True directly + newPostForm += headerNewsTabs('inbox', translate, usersPath, baseDir, True, userPages) # Close banner div newPostForm += '\n' @@ -798,7 +801,7 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {}, newPostForm += ' \n' newPostForm += '\n' - # Close "section" and "page" div + # Close "main" and "page" div newPostForm += '\n\n' if not reportUrl: diff --git a/webapp_frontscreen.py b/webapp_frontscreen.py index adfb0b24..daf4f274 100644 --- a/webapp_frontscreen.py +++ b/webapp_frontscreen.py @@ -9,12 +9,14 @@ __status__ = "Production" import os from utils import isSystemAccount from utils import getDomainFromActor +from utils import getConfigParam from person import personBoxJson -from webapp_utils import htmlHeaderWithExternalStyle +from webapp_utils import htmlHeaderWithExternalStyles from webapp_utils import htmlFooter from webapp_utils import getBannerFile from webapp_utils import htmlPostSeparator from webapp_utils import headerButtonsFrontScreen +from webapp_headerbuttons import headerNewsTabs from webapp_column_left import getLeftColumnContent from webapp_column_right import getRightColumnContent from webapp_post import individualPostAsHtml @@ -106,41 +108,61 @@ def htmlFrontScreen(rssIconAtTop: bool, if port: domainFull = domain + ':' + str(port) - loginButton = headerButtonsFrontScreen(translate, nickname, - 'features', authorized, - iconsAsButtons) - # If this is the news account then show a different banner - bannerFile, bannerFilename = \ - getBannerFile(baseDir, nickname, domain, theme) - profileHeaderStr = \ - '\n' - if loginButton: - profileHeaderStr += '
' + loginButton + '
\n' + bannerFile, bannerFilename = getBannerFile(baseDir, nickname, domain) - profileHeaderStr += '\n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileHeaderStr += ' \n' - profileFooterStr += ' \n' - profileFooterStr += ' \n' - profileFooterStr += ' \n' - profileFooterStr += '
\n' - profileHeaderStr += \ + profileHeaderStr = '
\n' + + # TODO: News instances should ignore personalised banners + # Currently uses the 'news' actor banner - as it remains unchanged + profileHeaderStr += (f"\t" + f"{translate['Features']}\n" + f"\t
\n" + f"\t\t#IndymediaBack\n" + f"\t
\n") + + # Show "tab" links instead of standard "buttons" + profileHeaderStr += headerNewsTabs('tlfeatures', translate, '/users/news', baseDir, authorized, None) + + # Close banner div + profileHeaderStr += '
\n' + + # TODO: Should probably use a more generic class, easier to re-use and help simplify CSS + # NOTE: Related also to class "page" added to 'webapp_create_post.py' + profileHeaderStr += '
\n' + + iconsPath = getIconsWebPath(baseDir) + leftColumnStr = \ getLeftColumnContent(baseDir, 'news', domainFull, httpPrefix, translate, - False, False, None, rssIconAtTop, True, - True, theme) - profileHeaderStr += '
\n' + iconsPath, False, + False, None, rssIconAtTop, True, + True) + profileHeaderStr += ' \n' profileStr = profileHeaderStr - cssFilename = baseDir + '/epicyon-profile.css' + cssFiles = [] + + # TODO: Clean up - default load only one base css file + # default css + cssFiles.append(baseDir + '/epicyon-profile.css') if os.path.isfile(baseDir + '/epicyon.css'): - cssFilename = baseDir + '/epicyon.css' + cssFiles[0] = baseDir + '/epicyon.css' + + # TODO: Clean up and remove this override + cssFiles[0] = 'base.css' + + # Get theme-specific css if exists - must be named '.css' + themeName = getConfigParam(baseDir, 'theme') + + themePath = f'{baseDir}/theme/{themeName}.css' + if os.path.isfile(themePath): + cssFiles.append('theme/' + themeName + '.css') + + # center column containing posts + profileStr += '
\n' licenseStr = '' bannerFile, bannerFilename = \ @@ -156,21 +178,27 @@ def htmlFrontScreen(rssIconAtTop: bool, showPublishedDateOnly, peertubeInstances) + licenseStr + # end of div main + profileStr += '
\n' + # Footer which is only used for system accounts - profileFooterStr = '
\n' - profileFooterStr += \ + + iconsPath = getIconsWebPath(baseDir) + rightColumnStr = \ getRightColumnContent(baseDir, 'news', domainFull, httpPrefix, translate, False, False, newswire, False, False, None, False, False, - False, True, authorized, True, theme) - profileFooterStr += '
\n' + False, True, authorized, True) + + profileFooterStr = '
' + \ + rightColumnStr + '
\n' + + # Close div page + profileFooterStr += '\n' profileStr = \ - htmlHeaderWithExternalStyle(cssFilename) + \ + htmlHeaderWithExternalStyles(cssFiles) + \ profileStr + profileFooterStr + htmlFooter() + return profileStr diff --git a/webapp_profile.py b/webapp_profile.py index 65d29a59..36e9f1b1 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -27,6 +27,7 @@ from session import getJson from posts import parseUserFeed from posts import getUserUrl from posts import getPersonBox +from posts import isModerator from donate import getDonationUrl from xmpp import getXmppAddress from matrix import getMatrixAddress @@ -42,7 +43,8 @@ from follow import isFollowerOfPerson from webapp_frontscreen import htmlFrontScreen from webapp_utils import scheduledPostsExist from webapp_utils import getPersonAvatarUrl -from webapp_utils import htmlHeaderWithExternalStyle +from webapp_utils import getIconsWebPath +from webapp_utils import htmlHeaderWithExternalStyle, htmlHeaderWithExternalStyles from webapp_utils import htmlFooter from webapp_utils import addEmojiToDisplayName from webapp_utils import getBannerFile @@ -50,6 +52,7 @@ from webapp_utils import htmlPostSeparator from webapp_utils import getBlogAddress from webapp_post import individualPostAsHtml from webapp_timeline import htmlIndividualShare +from webapp_headerbuttons import headerButtonsTimeline, headerNewsTabs def htmlProfileAfterSearch(cssCache: {}, @@ -1046,9 +1049,22 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, 'class="slider" name="skillValue' + \ str(skillCtr) + '" value="50">

' - cssFilename = baseDir + '/epicyon-profile.css' + cssFiles = [] + + # the css filename + cssFiles.append(baseDir + '/epicyon-profile.css') if os.path.isfile(baseDir + '/epicyon.css'): - cssFilename = baseDir + '/epicyon.css' + cssFiles[0] = baseDir + '/epicyon.css' + + # TODO: Clean up and remove this override + cssFiles[0] = 'base.css' + + # Get theme-specific css if exists - must be named '.css' + themeName = getConfigParam(baseDir, 'theme') + + themePath = f'{baseDir}/theme/{themeName}.css' + if os.path.isfile(themePath): + cssFiles.append('theme/' + themeName + '.css') moderatorsStr = '' themesDropdown = '' @@ -1186,15 +1202,60 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, 'style="height:200px">' + peertubeInstancesStr + \ '\n' - editProfileForm = htmlHeaderWithExternalStyle(cssFilename) + editProfileForm = htmlHeaderWithExternalStyles(cssFiles) + + usersPath = '/users/' + nickname # top banner - editProfileForm += \ - '\n' - editProfileForm += '\n' + editProfileForm += '
\n' + + if not defaultTimeline == 'tlfeatures': + editProfileForm += (f"\t" + f"{translate['Switch to timeline view']}\n") + else: + # TODO: News instances should ignore personalised banners + # Currently uses the 'news' actor banner - as it remains unchanged + editProfileForm += (f"\t" + f"{translate['Features']}\n" + f"\t
\n" + f"\t\t#IndymediaBack\n" + f"\t
\n") + + # Certain Epciyon pages should only be accessible via the 'User' page for News instances + userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \ + 'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \ + 'followers', 'newfollowers', 'newdm', 'newpost', 'newblog', 'newevent', 'editprofile'] + + # Full row "navbar" + if defaultTimeline == 'tlfeatures': + # Show "tab" links instead of standard "buttons" + # NOTE: It should be "safe" to assume that this code would not be running, + # unless the user was already deemed 'authorized', + # thus allowing us to pass True directly + editProfileForm += headerNewsTabs('editprofile', translate, usersPath, baseDir, True, userPages) + + # Close banner div + editProfileForm += '
\n' + + # TODO: Place form inside a "page" div for 'News' instances + # NOTE: Duplicate of code from webapp_create_post.py + editProfileForm += '
\n' + + moderator = isModerator(baseDir, nickname) + + # TODO: Add "User" links + if defaultTimeline == 'tlfeatures': + # TODO: Determine if "editprofile" is the appropriate 'boxName' + editProfileForm += \ + headerButtonsTimeline(defaultTimeline, 'editprofile', 1, + translate, usersPath, + False, moderator, + False, + baseDir, nickname, + domain, None, + True, userPages) + editProfileForm += '
\n' editProfileForm += \ '
\n") - # TODO: Include '/editprofile' link on 'User' page for 'News' instances - - # Certain Epciyon pages should only be accessible via the 'User' page for News instances # TODO: The 'new...' pages appear to require handling elsewhere userPages = ['inbox', 'outbox', 'dm', 'tlreplies', 'tlblogs', 'tlmedia', 'tlshares', \ 'tlsaves', 'tlevents', 'tlbookmarks', 'moderation', 'search', \ - 'followers', 'newfollowers', 'newdm', 'newpost', 'newblog', 'newevent'] + 'followers', 'newfollowers', 'newdm', 'newpost', 'newblog', 'newevent', 'editprofile'] # Full row "navbar" if defaultTimeline == 'tlfeatures': # Show "tab" links instead of standard "buttons" - tlStr += headerNewsTabs(boxName, translate, usersPath, baseDir, userPages) + tlStr += headerNewsTabs(boxName, translate, usersPath, baseDir, authorized, userPages) # Close banner div tlStr += '
\n'