From ec46767a2738ab49522745b4636c80af9b49085b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 17 Nov 2020 20:40:36 +0000 Subject: [PATCH] Separate header buttons --- webapp_headerbuttons.py | 330 +++++++++++++++++++++++++++++++++++++++ webapp_timeline.py | 332 +--------------------------------------- webapp_utils.py | 11 ++ 3 files changed, 343 insertions(+), 330 deletions(-) create mode 100644 webapp_headerbuttons.py diff --git a/webapp_headerbuttons.py b/webapp_headerbuttons.py new file mode 100644 index 000000000..9fea8bd2b --- /dev/null +++ b/webapp_headerbuttons.py @@ -0,0 +1,330 @@ +__filename__ = "webapp_headerbuttons.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.1.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" + + +import time +from datetime import datetime +from happening import todaysEventsCheck +from happening import thisWeeksEventsCheck +from webapp_utils import htmlHighlightLabel + + +def headerButtonsTimeline(defaultTimeline: str, + boxName: str, + pageNumber: int, + translate: {}, + usersPath: str, + mediaButton: str, + blogsButton: str, + newsButton: str, + inboxButton: str, + dmButton: str, + newDM: str, + repliesButton: str, + newReply: str, + minimal: bool, + sentButton: str, + sharesButtonStr: str, + bookmarksButtonStr: str, + eventsButtonStr: str, + moderationButtonStr: str, + newPostButtonStr: str, + baseDir: str, + nickname: str, domain: str, + iconsPath: str, + timelineStartTime, + newCalendarEvent: bool, + calendarPath: str, + calendarImage: str, + followApprovals: str, + iconsAsButtons: bool) -> str: + """Returns the header at the top of the timeline, containing + buttons for inbox, outbox, search, calendar, etc + """ + # start of the button header with inbox, outbox, etc + tlStr = '
\n' + # first button + if defaultTimeline == 'tlmedia': + tlStr += \ + '' + elif defaultTimeline == 'tlblogs': + tlStr += \ + '' + elif defaultTimeline == 'tlnews': + tlStr += \ + '' + else: + tlStr += \ + '' + + # if this is a news instance and we are viewing the news timeline + newsHeader = False + if defaultTimeline == 'tlnews' and boxName == 'tlnews': + newsHeader = True + + if not newsHeader: + tlStr += \ + '' + + tlStr += \ + '' + + # typically the media button + if defaultTimeline != 'tlmedia': + if not minimal and not newsHeader: + tlStr += \ + '' + else: + if not minimal: + tlStr += \ + '' + + isFeaturesTimeline = \ + defaultTimeline == 'tlnews' and boxName == 'tlnews' + + if not isFeaturesTimeline: + # typically the blogs button + # but may change if this is a blogging oriented instance + if defaultTimeline != 'tlblogs': + if not minimal and not isFeaturesTimeline: + titleStr = translate['Blogs'] + if defaultTimeline == 'tlnews': + titleStr = translate['Article'] + tlStr += \ + '' + else: + if not minimal: + tlStr += \ + '' + + # typically the news button + # but may change if this is a news oriented instance + if defaultTimeline != 'tlnews': + tlStr += \ + '' + else: + if not newsHeader: + tlStr += \ + '' + + # show todays events buttons on the first inbox page + happeningStr = '' + if boxName == 'inbox' and pageNumber == 1: + if todaysEventsCheck(baseDir, nickname, domain): + now = datetime.now() + + # happening today button + if not iconsAsButtons: + happeningStr += \ + '' + \ + '' + else: + happeningStr += \ + '' + \ + '' + + # happening this week button + if thisWeeksEventsCheck(baseDir, nickname, domain): + if not iconsAsButtons: + happeningStr += \ + '' + else: + happeningStr += \ + '' + else: + # happening this week button + if thisWeeksEventsCheck(baseDir, nickname, domain): + if not iconsAsButtons: + happeningStr += \ + '' + else: + happeningStr += \ + '' + + if not newsHeader: + # button for the outbox + tlStr += \ + '' + + # add other buttons + tlStr += \ + sharesButtonStr + bookmarksButtonStr + eventsButtonStr + \ + moderationButtonStr + happeningStr + newPostButtonStr + + if not newsHeader: + if not iconsAsButtons: + # the search icon + tlStr += \ + '| ' + \
+                translate['Search and follow'] + \
+                '' + else: + # the search button + tlStr += \ + '' + + # benchmark 5 + timeDiff = int((time.time() - timelineStartTime) * 1000) + if timeDiff > 100: + print('TIMELINE TIMING ' + boxName + ' 5 = ' + str(timeDiff)) + + # the calendar button + if not isFeaturesTimeline: + calendarAltText = translate['Calendar'] + if newCalendarEvent: + # indicate that the calendar icon is highlighted + calendarAltText = '*' + calendarAltText + '*' + if not iconsAsButtons: + tlStr += \ + ' | ' + calendarAltText + \
+                '\n' + else: + tlStr += \ + '' + + if not newsHeader: + # the show/hide button, for a simpler header appearance + if not iconsAsButtons: + tlStr += \ + ' | ' + translate['Show/Hide Buttons'] + \
+                '\n' + else: + tlStr += \ + '' + + if newsHeader: + tlStr += \ + '' + \ + '' + + # the newswire button to show right column links + if not iconsAsButtons: + tlStr += \ + '' + \ + '| ' + translate['News'] + \
+            '' + else: + # NOTE: deliberately no \n at end of line + tlStr += \ + '' + + # the links button to show left column links + if not iconsAsButtons: + tlStr += \ + '' + \ + '| ' + translate['Edit Links'] + \
+            '' + else: + # NOTE: deliberately no \n at end of line + tlStr += \ + '' + + if newsHeader: + tlStr += \ + '' + \ + '' + + if not newsHeader: + tlStr += followApprovals + + if not iconsAsButtons: + # end of headericons div + tlStr += '
' + + # end of the button header with inbox, outbox, etc + tlStr += ' \n' + return tlStr diff --git a/webapp_timeline.py b/webapp_timeline.py index 942b7f6ed..e2857a63a 100644 --- a/webapp_timeline.py +++ b/webapp_timeline.py @@ -7,23 +7,22 @@ __email__ = "bob@freedombone.net" __status__ = "Production" import os -from datetime import datetime import time from utils import removeIdEnding from follow import followerApprovalActive from person import isPersonSnoozed -from happening import todaysEventsCheck -from happening import thisWeeksEventsCheck from webapp_utils import getIconsWebPath from webapp_utils import htmlPostSeparator from webapp_utils import getBannerFile from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_utils import sharesTimelineJson +from webapp_utils import htmlHighlightLabel from webapp_post import preparePostFromHtmlCache from webapp_post import individualPostAsHtml from webapp_column_left import getLeftColumnContent from webapp_column_right import getRightColumnContent +from webapp_headerbuttons import headerButtonsTimeline from posts import isModerator from posts import isEditor @@ -712,333 +711,6 @@ def htmlSharesTimeline(translate: {}, pageNumber: int, itemsPerPage: int, return timelineStr -def htmlHighlightLabel(label: str, highlight: bool) -> str: - """If the give text should be highlighted then return - the appropriate markup. - This is so that in shell browsers, like lynx, it's possible - to see if the replies or DM button are highlighted. - """ - if not highlight: - return label - return '*' + str(label) + '*' - - -def headerButtonsTimeline(defaultTimeline: str, - boxName: str, - pageNumber: int, - translate: {}, - usersPath: str, - mediaButton: str, - blogsButton: str, - newsButton: str, - inboxButton: str, - dmButton: str, - newDM: str, - repliesButton: str, - newReply: str, - minimal: bool, - sentButton: str, - sharesButtonStr: str, - bookmarksButtonStr: str, - eventsButtonStr: str, - moderationButtonStr: str, - newPostButtonStr: str, - baseDir: str, - nickname: str, domain: str, - iconsPath: str, - timelineStartTime, - newCalendarEvent: bool, - calendarPath: str, - calendarImage: str, - followApprovals: str, - iconsAsButtons: bool) -> str: - """Returns the header at the top of the timeline, containing - buttons for inbox, outbox, search, calendar, etc - """ - # start of the button header with inbox, outbox, etc - tlStr = '
\n' - # first button - if defaultTimeline == 'tlmedia': - tlStr += \ - '' - elif defaultTimeline == 'tlblogs': - tlStr += \ - '' - elif defaultTimeline == 'tlnews': - tlStr += \ - '' - else: - tlStr += \ - '' - - # if this is a news instance and we are viewing the news timeline - newsHeader = False - if defaultTimeline == 'tlnews' and boxName == 'tlnews': - newsHeader = True - - if not newsHeader: - tlStr += \ - '' - - tlStr += \ - '' - - # typically the media button - if defaultTimeline != 'tlmedia': - if not minimal and not newsHeader: - tlStr += \ - '' - else: - if not minimal: - tlStr += \ - '' - - isFeaturesTimeline = \ - defaultTimeline == 'tlnews' and boxName == 'tlnews' - - if not isFeaturesTimeline: - # typically the blogs button - # but may change if this is a blogging oriented instance - if defaultTimeline != 'tlblogs': - if not minimal and not isFeaturesTimeline: - titleStr = translate['Blogs'] - if defaultTimeline == 'tlnews': - titleStr = translate['Article'] - tlStr += \ - '' - else: - if not minimal: - tlStr += \ - '' - - # typically the news button - # but may change if this is a news oriented instance - if defaultTimeline != 'tlnews': - tlStr += \ - '' - else: - if not newsHeader: - tlStr += \ - '' - - # show todays events buttons on the first inbox page - happeningStr = '' - if boxName == 'inbox' and pageNumber == 1: - if todaysEventsCheck(baseDir, nickname, domain): - now = datetime.now() - - # happening today button - if not iconsAsButtons: - happeningStr += \ - '' + \ - '' - else: - happeningStr += \ - '' + \ - '' - - # happening this week button - if thisWeeksEventsCheck(baseDir, nickname, domain): - if not iconsAsButtons: - happeningStr += \ - '' - else: - happeningStr += \ - '' - else: - # happening this week button - if thisWeeksEventsCheck(baseDir, nickname, domain): - if not iconsAsButtons: - happeningStr += \ - '' - else: - happeningStr += \ - '' - - if not newsHeader: - # button for the outbox - tlStr += \ - '' - - # add other buttons - tlStr += \ - sharesButtonStr + bookmarksButtonStr + eventsButtonStr + \ - moderationButtonStr + happeningStr + newPostButtonStr - - if not newsHeader: - if not iconsAsButtons: - # the search icon - tlStr += \ - '| ' + \
-                translate['Search and follow'] + \
-                '' - else: - # the search button - tlStr += \ - '' - - # benchmark 5 - timeDiff = int((time.time() - timelineStartTime) * 1000) - if timeDiff > 100: - print('TIMELINE TIMING ' + boxName + ' 5 = ' + str(timeDiff)) - - # the calendar button - if not isFeaturesTimeline: - calendarAltText = translate['Calendar'] - if newCalendarEvent: - # indicate that the calendar icon is highlighted - calendarAltText = '*' + calendarAltText + '*' - if not iconsAsButtons: - tlStr += \ - ' | ' + calendarAltText + \
-                '\n' - else: - tlStr += \ - '' - - if not newsHeader: - # the show/hide button, for a simpler header appearance - if not iconsAsButtons: - tlStr += \ - ' | ' + translate['Show/Hide Buttons'] + \
-                '\n' - else: - tlStr += \ - '' - - if newsHeader: - tlStr += \ - '' + \ - '' - - # the newswire button to show right column links - if not iconsAsButtons: - tlStr += \ - '' + \ - '| ' + translate['News'] + \
-            '' - else: - # NOTE: deliberately no \n at end of line - tlStr += \ - '' - - # the links button to show left column links - if not iconsAsButtons: - tlStr += \ - '' + \ - '| ' + translate['Edit Links'] + \
-            '' - else: - # NOTE: deliberately no \n at end of line - tlStr += \ - '' - - if newsHeader: - tlStr += \ - '' + \ - '' - - if not newsHeader: - tlStr += followApprovals - - if not iconsAsButtons: - # end of headericons div - tlStr += '
' - - # end of the button header with inbox, outbox, etc - tlStr += ' \n' - return tlStr - - def htmlShares(cssCache: {}, defaultTimeline: str, recentPostsCache: {}, maxRecentPosts: int, translate: {}, pageNumber: int, itemsPerPage: int, diff --git a/webapp_utils.py b/webapp_utils.py index 8b3c8bc6a..35a4ee163 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -808,3 +808,14 @@ def headerButtonsFrontScreen(translate: {}, headerStr + \ ' \n' return headerStr + + +def htmlHighlightLabel(label: str, highlight: bool) -> str: + """If the given text should be highlighted then return + the appropriate markup. + This is so that in shell browsers, like lynx, it's possible + to see if the replies or DM button are highlighted. + """ + if not highlight: + return label + return '*' + str(label) + '*'