Snake case

merge-requests/30/head
Bob Mottram 2022-01-03 23:24:44 +00:00
parent 43379ae568
commit 11ebc26756
1 changed files with 131 additions and 131 deletions

View File

@ -18,155 +18,155 @@ from webapp_utils import html_highlight_label
def header_buttons_timeline(default_timeline: str, def header_buttons_timeline(default_timeline: str,
boxName: str, box_name: str,
pageNumber: int, page_number: int,
translate: {}, translate: {},
usersPath: str, users_path: str,
mediaButton: str, mediaButton: str,
blogsButton: str, blogs_button: str,
featuresButton: str, features_button: str,
newsButton: str, news_button: str,
inboxButton: str, inbox_button: str,
dmButton: str, dm_button: str,
newDM: str, new_dm: str,
repliesButton: str, replies_button: str,
newReply: str, new_reply: str,
minimal: bool, minimal: bool,
sentButton: str, sent_button: str,
sharesButtonStr: str, shares_button_str: str,
wantedButtonStr: str, wanted_button_str: str,
bookmarksButtonStr: str, bookmarks_button_str: str,
eventsButtonStr: str, events_button_str: str,
moderationButtonStr: str, moderation_button_str: str,
newPostButtonStr: str, new_post_button_str: str,
base_dir: str, base_dir: str,
nickname: str, domain: str, nickname: str, domain: str,
timelineStartTime, timeline_start_time,
newCalendarEvent: bool, new_calendar_event: bool,
calendarPath: str, calendar_path: str,
calendarImage: str, calendar_image: str,
followApprovals: str, follow_approvals: str,
icons_as_buttons: bool, icons_as_buttons: bool,
access_keys: {}) -> str: access_keys: {}) -> str:
"""Returns the header at the top of the timeline, containing """Returns the header at the top of the timeline, containing
buttons for inbox, outbox, search, calendar, etc buttons for inbox, outbox, search, calendar, etc
""" """
# start of the button header with inbox, outbox, etc # start of the button header with inbox, outbox, etc
tlStr = '<div class="containerHeader"><nav>\n' tl_str = '<div class="containerHeader"><nav>\n'
# first button # first button
if default_timeline == 'tlmedia': if default_timeline == 'tlmedia':
tlStr += \ tl_str += \
'<a href="' + usersPath + '/tlmedia" tabindex="-1" ' + \ '<a href="' + users_path + '/tlmedia" tabindex="-1" ' + \
'accesskey="' + access_keys['menuMedia'] + '"' + \ 'accesskey="' + access_keys['menuMedia'] + '"' + \
'><button class="' + \ '><button class="' + \
mediaButton + '"><span>' + translate['Media'] + \ mediaButton + '"><span>' + translate['Media'] + \
'</span></button></a>' '</span></button></a>'
elif default_timeline == 'tlblogs': elif default_timeline == 'tlblogs':
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/tlblogs" tabindex="-1"><button class="' + \ '/tlblogs" tabindex="-1"><button class="' + \
blogsButton + '"><span>' + translate['Blogs'] + \ blogs_button + '"><span>' + translate['Blogs'] + \
'</span></button></a>' '</span></button></a>'
elif default_timeline == 'tlfeatures': elif default_timeline == 'tlfeatures':
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/tlfeatures" tabindex="-1"><button class="' + \ '/tlfeatures" tabindex="-1"><button class="' + \
featuresButton + '"><span>' + translate['Features'] + \ features_button + '"><span>' + translate['Features'] + \
'</span></button></a>' '</span></button></a>'
else: else:
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/inbox" tabindex="-1"><button class="' + \ '/inbox" tabindex="-1"><button class="' + \
inboxButton + '"><span>' + \ inbox_button + '"><span>' + \
translate['Inbox'] + '</span></button></a>' translate['Inbox'] + '</span></button></a>'
# if this is a news instance and we are viewing the news timeline # if this is a news instance and we are viewing the news timeline
featuresHeader = False features_header = False
if default_timeline == 'tlfeatures' and boxName == 'tlfeatures': if default_timeline == 'tlfeatures' and box_name == 'tlfeatures':
featuresHeader = True features_header = True
if not featuresHeader: if not features_header:
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/dm" tabindex="-1"><button class="' + dmButton + \ '/dm" tabindex="-1"><button class="' + dm_button + \
'"><span>' + html_highlight_label(translate['DM'], newDM) + \ '"><span>' + html_highlight_label(translate['DM'], new_dm) + \
'</span></button></a>' '</span></button></a>'
repliesIndexFilename = \ replies_index_filename = \
acct_dir(base_dir, nickname, domain) + '/tlreplies.index' acct_dir(base_dir, nickname, domain) + '/tlreplies.index'
if os.path.isfile(repliesIndexFilename): if os.path.isfile(replies_index_filename):
tlStr += \ tl_str += \
'<a href="' + usersPath + '/tlreplies" tabindex="-1">' + \ '<a href="' + users_path + '/tlreplies" tabindex="-1">' + \
'<button class="' + repliesButton + '"><span>' + \ '<button class="' + replies_button + '"><span>' + \
html_highlight_label(translate['Replies'], newReply) + \ html_highlight_label(translate['Replies'], new_reply) + \
'</span></button></a>' '</span></button></a>'
# typically the media button # typically the media button
if default_timeline != 'tlmedia': if default_timeline != 'tlmedia':
if not minimal and not featuresHeader: if not minimal and not features_header:
tlStr += \ tl_str += \
'<a href="' + usersPath + '/tlmedia" tabindex="-1" ' + \ '<a href="' + users_path + '/tlmedia" tabindex="-1" ' + \
'accesskey="' + access_keys['menuMedia'] + '">' + \ 'accesskey="' + access_keys['menuMedia'] + '">' + \
'<button class="' + \ '<button class="' + \
mediaButton + '"><span>' + translate['Media'] + \ mediaButton + '"><span>' + translate['Media'] + \
'</span></button></a>' '</span></button></a>'
else: else:
if not minimal: if not minimal:
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/inbox" tabindex="-1"><button class="' + \ '/inbox" tabindex="-1"><button class="' + \
inboxButton + '"><span>' + translate['Inbox'] + \ inbox_button + '"><span>' + translate['Inbox'] + \
'</span></button></a>' '</span></button></a>'
if not featuresHeader: if not features_header:
# typically the blogs button # typically the blogs button
# but may change if this is a blogging oriented instance # but may change if this is a blogging oriented instance
if default_timeline != 'tlblogs': if default_timeline != 'tlblogs':
if not minimal: if not minimal:
titleStr = translate['Blogs'] title_str = translate['Blogs']
if default_timeline == 'tlfeatures': if default_timeline == 'tlfeatures':
titleStr = translate['Article'] title_str = translate['Article']
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/tlblogs" tabindex="-1"><button class="' + \ '/tlblogs" tabindex="-1"><button class="' + \
blogsButton + '"><span>' + titleStr + \ blogs_button + '"><span>' + title_str + \
'</span></button></a>' '</span></button></a>'
else: else:
if not minimal: if not minimal:
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/inbox" tabindex="-1"><button class="' + \ '/inbox" tabindex="-1"><button class="' + \
inboxButton + '"><span>' + translate['Inbox'] + \ inbox_button + '"><span>' + translate['Inbox'] + \
'</span></button></a>' '</span></button></a>'
# typically the news button # typically the news button
# but may change if this is a news oriented instance # but may change if this is a news oriented instance
if default_timeline == 'tlfeatures': if default_timeline == 'tlfeatures':
if not featuresHeader: if not features_header:
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/inbox" tabindex="-1"><button class="' + \ '/inbox" tabindex="-1"><button class="' + \
inboxButton + '"><span>' + translate['Inbox'] + \ inbox_button + '"><span>' + translate['Inbox'] + \
'</span></button></a>' '</span></button></a>'
# show todays events buttons on the first inbox page # show todays events buttons on the first inbox page
happeningStr = '' happening_str = ''
if boxName == 'inbox' and pageNumber == 1: if box_name == 'inbox' and page_number == 1:
now = datetime.now() now = datetime.now()
tomorrow = datetime.now() + timedelta(1) tomorrow = datetime.now() + timedelta(1)
twodays = datetime.now() + timedelta(2) twodays = datetime.now() + timedelta(2)
if day_events_check(base_dir, nickname, domain, now): if day_events_check(base_dir, nickname, domain, now):
# happening today button # happening today button
if not icons_as_buttons: if not icons_as_buttons:
happeningStr += \ happening_str += \
'<a href="' + usersPath + '/calendar?year=' + \ '<a href="' + users_path + '/calendar?year=' + \
str(now.year) + '?month=' + str(now.month) + \ str(now.year) + '?month=' + str(now.month) + \
'?day=' + str(now.day) + '" tabindex="-1">' + \ '?day=' + str(now.day) + '" tabindex="-1">' + \
'<button class="buttonevent">' + \ '<button class="buttonevent">' + \
translate['Happening Today'] + '</button></a>' translate['Happening Today'] + '</button></a>'
else: else:
happeningStr += \ happening_str += \
'<a href="' + usersPath + '/calendar?year=' + \ '<a href="' + users_path + '/calendar?year=' + \
str(now.year) + '?month=' + str(now.month) + \ str(now.year) + '?month=' + str(now.month) + \
'?day=' + str(now.day) + '" tabindex="-1">' + \ '?day=' + str(now.day) + '" tabindex="-1">' + \
'<button class="button">' + \ '<button class="button">' + \
@ -175,51 +175,51 @@ def header_buttons_timeline(default_timeline: str,
elif day_events_check(base_dir, nickname, domain, tomorrow): elif day_events_check(base_dir, nickname, domain, tomorrow):
# happening tomorrow button # happening tomorrow button
if not icons_as_buttons: if not icons_as_buttons:
happeningStr += \ happening_str += \
'<a href="' + usersPath + '/calendar?year=' + \ '<a href="' + users_path + '/calendar?year=' + \
str(tomorrow.year) + '?month=' + str(tomorrow.month) + \ str(tomorrow.year) + '?month=' + str(tomorrow.month) + \
'?day=' + str(tomorrow.day) + '" tabindex="-1">' + \ '?day=' + str(tomorrow.day) + '" tabindex="-1">' + \
'<button class="buttonevent">' + \ '<button class="buttonevent">' + \
translate['Happening Tomorrow'] + '</button></a>' translate['Happening Tomorrow'] + '</button></a>'
else: else:
happeningStr += \ happening_str += \
'<a href="' + usersPath + '/calendar?year=' + \ '<a href="' + users_path + '/calendar?year=' + \
str(tomorrow.year) + '?month=' + str(tomorrow.month) + \ str(tomorrow.year) + '?month=' + str(tomorrow.month) + \
'?day=' + str(tomorrow.day) + '" tabindex="-1">' + \ '?day=' + str(tomorrow.day) + '" tabindex="-1">' + \
'<button class="button">' + \ '<button class="button">' + \
translate['Happening Tomorrow'] + '</button></a>' translate['Happening Tomorrow'] + '</button></a>'
elif day_events_check(base_dir, nickname, domain, twodays): elif day_events_check(base_dir, nickname, domain, twodays):
if not icons_as_buttons: if not icons_as_buttons:
happeningStr += \ happening_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/calendar" tabindex="-1">' + \ '/calendar" tabindex="-1">' + \
'<button class="buttonevent">' + \ '<button class="buttonevent">' + \
translate['Happening This Week'] + '</button></a>' translate['Happening This Week'] + '</button></a>'
else: else:
happeningStr += \ happening_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/calendar" tabindex="-1">' + \ '/calendar" tabindex="-1">' + \
'<button class="button">' + \ '<button class="button">' + \
translate['Happening This Week'] + '</button></a>' translate['Happening This Week'] + '</button></a>'
if not featuresHeader: if not features_header:
# button for the outbox # button for the outbox
tlStr += \ tl_str += \
'<a href="' + usersPath + '/outbox"><button class="' + \ '<a href="' + users_path + '/outbox"><button class="' + \
sentButton + '" tabindex="-1"><span>' + translate['Sent'] + \ sent_button + '" tabindex="-1"><span>' + translate['Sent'] + \
'</span></button></a>' '</span></button></a>'
# add other buttons # add other buttons
tlStr += \ tl_str += \
sharesButtonStr + wantedButtonStr + bookmarksButtonStr + \ shares_button_str + wanted_button_str + bookmarks_button_str + \
eventsButtonStr + \ events_button_str + \
moderationButtonStr + happeningStr + newPostButtonStr moderation_button_str + happening_str + new_post_button_str
if not featuresHeader: if not features_header:
if not icons_as_buttons: if not icons_as_buttons:
# the search icon # the search icon
tlStr += \ tl_str += \
'<a class="imageAnchor" href="' + usersPath + \ '<a class="imageAnchor" href="' + users_path + \
'/search"><img loading="lazy" src="/' + \ '/search"><img loading="lazy" src="/' + \
'icons/search.png" title="' + \ 'icons/search.png" title="' + \
translate['Search and follow'] + '" alt="| ' + \ translate['Search and follow'] + '" alt="| ' + \
@ -227,110 +227,110 @@ def header_buttons_timeline(default_timeline: str,
'" class="timelineicon"/></a>' '" class="timelineicon"/></a>'
else: else:
# the search button # the search button
tlStr += \ tl_str += \
'<a href="' + usersPath + \ '<a href="' + users_path + \
'/search" tabindex="-1"><button class="button">' + \ '/search" tabindex="-1"><button class="button">' + \
'<span>' + translate['Search'] + \ '<span>' + translate['Search'] + \
'</span></button></a>' '</span></button></a>'
# benchmark 5 # benchmark 5
time_diff = int((time.time() - timelineStartTime) * 1000) time_diff = int((time.time() - timeline_start_time) * 1000)
if time_diff > 100: if time_diff > 100:
print('TIMELINE TIMING ' + boxName + ' 5 = ' + str(time_diff)) print('TIMELINE TIMING ' + box_name + ' 5 = ' + str(time_diff))
# the calendar button # the calendar button
if not featuresHeader: if not features_header:
calendarAltText = translate['Calendar'] calendar_alt_text = translate['Calendar']
if newCalendarEvent: if new_calendar_event:
# indicate that the calendar icon is highlighted # indicate that the calendar icon is highlighted
calendarAltText = '*' + calendarAltText + '*' calendar_alt_text = '*' + calendar_alt_text + '*'
if not icons_as_buttons: if not icons_as_buttons:
tlStr += \ tl_str += \
' <a class="imageAnchor" href="' + \ ' <a class="imageAnchor" href="' + \
usersPath + calendarPath + \ users_path + calendar_path + \
'"><img loading="lazy" src="/icons/' + \ '"><img loading="lazy" src="/icons/' + \
calendarImage + '" title="' + translate['Calendar'] + \ calendar_image + '" title="' + translate['Calendar'] + \
'" alt="| ' + calendarAltText + \ '" alt="| ' + calendar_alt_text + \
'" class="timelineicon"/></a>\n' '" class="timelineicon"/></a>\n'
else: else:
tlStr += \ tl_str += \
'<a href="' + usersPath + calendarPath + \ '<a href="' + users_path + calendar_path + \
'" tabindex="-1"><button class="button">' + \ '" tabindex="-1"><button class="button">' + \
'<span>' + translate['Calendar'] + \ '<span>' + translate['Calendar'] + \
'</span></button></a>' '</span></button></a>'
if not featuresHeader: if not features_header:
# the show/hide button, for a simpler header appearance # the show/hide button, for a simpler header appearance
if not icons_as_buttons: if not icons_as_buttons:
tlStr += \ tl_str += \
' <a class="imageAnchor" href="' + \ ' <a class="imageAnchor" href="' + \
usersPath + '/minimal' + \ users_path + '/minimal' + \
'"><img loading="lazy" src="/icons' + \ '"><img loading="lazy" src="/icons' + \
'/showhide.png" title="' + translate['Show/Hide Buttons'] + \ '/showhide.png" title="' + translate['Show/Hide Buttons'] + \
'" alt="| ' + translate['Show/Hide Buttons'] + \ '" alt="| ' + translate['Show/Hide Buttons'] + \
'" class="timelineicon"/></a>\n' '" class="timelineicon"/></a>\n'
else: else:
tlStr += \ tl_str += \
'<a href="' + usersPath + '/minimal' + \ '<a href="' + users_path + '/minimal' + \
'" tabindex="-1"><button class="button">' + \ '" tabindex="-1"><button class="button">' + \
'<span>' + translate['Show/Hide Buttons'] + \ '<span>' + translate['Show/Hide Buttons'] + \
'</span></button></a>' '</span></button></a>'
if featuresHeader: if features_header:
tlStr += \ tl_str += \
'<a href="' + usersPath + '/inbox" tabindex="-1">' + \ '<a href="' + users_path + '/inbox" tabindex="-1">' + \
'<button class="button">' + \ '<button class="button">' + \
'<span>' + translate['User'] + '</span></button></a>' '<span>' + translate['User'] + '</span></button></a>'
# the newswire button to show right column links # the newswire button to show right column links
if not icons_as_buttons: if not icons_as_buttons:
tlStr += \ tl_str += \
'<a class="imageAnchorMobile" href="' + \ '<a class="imageAnchorMobile" href="' + \
usersPath + '/newswiremobile">' + \ users_path + '/newswiremobile">' + \
'<img loading="lazy" src="/icons' + \ '<img loading="lazy" src="/icons' + \
'/newswire.png" title="' + translate['News'] + \ '/newswire.png" title="' + translate['News'] + \
'" alt="| ' + translate['News'] + \ '" alt="| ' + translate['News'] + \
'" class="timelineicon"/></a>' '" class="timelineicon"/></a>'
else: else:
# NOTE: deliberately no \n at end of line # NOTE: deliberately no \n at end of line
tlStr += \ tl_str += \
'<a href="' + \ '<a href="' + \
usersPath + '/newswiremobile' + \ users_path + '/newswiremobile' + \
'" tabindex="-1"><button class="buttonMobile">' + \ '" tabindex="-1"><button class="buttonMobile">' + \
'<span>' + translate['Newswire'] + \ '<span>' + translate['Newswire'] + \
'</span></button></a>' '</span></button></a>'
# the links button to show left column links # the links button to show left column links
if not icons_as_buttons: if not icons_as_buttons:
tlStr += \ tl_str += \
'<a class="imageAnchorMobile" href="' + \ '<a class="imageAnchorMobile" href="' + \
usersPath + '/linksmobile">' + \ users_path + '/linksmobile">' + \
'<img loading="lazy" src="/icons' + \ '<img loading="lazy" src="/icons' + \
'/links.png" title="' + translate['Edit Links'] + \ '/links.png" title="' + translate['Edit Links'] + \
'" alt="| ' + translate['Edit Links'] + \ '" alt="| ' + translate['Edit Links'] + \
'" class="timelineicon"/></a>' '" class="timelineicon"/></a>'
else: else:
# NOTE: deliberately no \n at end of line # NOTE: deliberately no \n at end of line
tlStr += \ tl_str += \
'<a href="' + \ '<a href="' + \
usersPath + '/linksmobile' + \ users_path + '/linksmobile' + \
'" tabindex="-1"><button class="buttonMobile">' + \ '" tabindex="-1"><button class="buttonMobile">' + \
'<span>' + translate['Links'] + \ '<span>' + translate['Links'] + \
'</span></button></a>' '</span></button></a>'
if featuresHeader: if features_header:
tlStr += \ tl_str += \
'<a href="' + usersPath + '/editprofile" tabindex="-1">' + \ '<a href="' + users_path + '/editprofile" tabindex="-1">' + \
'<button class="buttonDesktop">' + \ '<button class="buttonDesktop">' + \
'<span>' + translate['Settings'] + '</span></button></a>' '<span>' + translate['Settings'] + '</span></button></a>'
if not featuresHeader: if not features_header:
tlStr += followApprovals tl_str += follow_approvals
if not icons_as_buttons: if not icons_as_buttons:
# end of headericons div # end of headericons div
tlStr += '</div>' tl_str += '</div>'
# end of the button header with inbox, outbox, etc # end of the button header with inbox, outbox, etc
tlStr += ' </nav></div>\n' tl_str += ' </nav></div>\n'
return tlStr return tl_str