From f2b734ca8d135474af797dbe87b89375ee802d38 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 3 Jan 2022 22:37:22 +0000 Subject: [PATCH] Snake case --- webapp_column_right.py | 522 ++++++++++++++++++++--------------------- 1 file changed, 261 insertions(+), 261 deletions(-) diff --git a/webapp_column_right.py b/webapp_column_right.py index 695d63c36..1940f307d 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -33,179 +33,179 @@ from webapp_utils import header_buttons_front_screen from webapp_utils import edit_text_field -def _votes_indicator(totalVotes: int, positive_voting: bool) -> str: +def _votes_indicator(total_votes: int, positive_voting: bool) -> str: """Returns an indicator of the number of votes on a newswire item """ - if totalVotes <= 0: + if total_votes <= 0: return '' - totalVotesStr = ' ' - for v in range(totalVotes): + total_votes_str = ' ' + for _ in range(total_votes): if positive_voting: - totalVotesStr += '✓' + total_votes_str += '✓' else: - totalVotesStr += '✗' - return totalVotesStr + total_votes_str += '✗' + return total_votes_str def get_right_column_content(base_dir: str, nickname: str, domain_full: str, http_prefix: str, translate: {}, moderator: bool, editor: bool, newswire: {}, positive_voting: bool, - showBackButton: bool, timelinePath: str, - showPublishButton: bool, + show_back_button: bool, timeline_path: str, + show_publish_button: bool, show_publish_as_icon: bool, rss_icon_at_top: bool, publish_button_at_top: bool, authorized: bool, - showHeaderImage: bool, + show_header_image: bool, theme: str, default_timeline: str, access_keys: {}) -> str: """Returns html content for the right column """ - htmlStr = '' + html_str = '' domain = remove_domain_port(domain_full) if authorized: # only show the publish button if logged in, otherwise replace it with # a login button - titleStr = translate['Publish a blog article'] + title_str = translate['Publish a blog article'] if default_timeline == 'tlfeatures': - titleStr = translate['Publish a news article'] - publishButtonStr = \ + title_str = translate['Publish a news article'] + publish_button_str = \ ' ' + \ '\n' else: # if not logged in then replace the publish button with # a login button - publishButtonStr = \ + publish_button_str = \ ' \n' # show publish button at the top if needed if publish_button_at_top: - htmlStr += '
' + publishButtonStr + '
' + html_str += '
' + publish_button_str + '
' # show a column header image, eg. title of the theme or newswire banner - editImageClass = '' - if showHeaderImage: - rightImageFile, rightColumnImageFilename = \ + edit_image_class = '' + if show_header_image: + right_image_file, right_column_image_filename = \ get_right_image_file(base_dir, nickname, domain, theme) # show the image at the top of the column - editImageClass = 'rightColEdit' - if os.path.isfile(rightColumnImageFilename): - editImageClass = 'rightColEditImage' - htmlStr += \ + edit_image_class = 'rightColEdit' + if os.path.isfile(right_column_image_filename): + edit_image_class = 'rightColEditImage' + html_str += \ '\n
\n' + \ ' \n' + \ + nickname + '/' + right_image_file + '" />\n' + \ '
\n' - if showPublishButton or editor or rss_icon_at_top: - if not showHeaderImage: - htmlStr += '
' + if show_publish_button or editor or rss_icon_at_top: + if not show_header_image: + html_str += '
' - if editImageClass == 'rightColEdit': - htmlStr += '\n
\n' + if edit_image_class == 'rightColEdit': + html_str += '\n
\n' # whether to show a back icon # This is probably going to be osolete soon - if showBackButton: - htmlStr += \ - ' ' + \ + if show_back_button: + html_str += \ + ' ' + \ '\n' - if showPublishButton and not publish_button_at_top: + if show_publish_button and not publish_button_at_top: if not show_publish_as_icon: - htmlStr += publishButtonStr + html_str += publish_button_str # show the edit icon if editor: if os.path.isfile(base_dir + '/accounts/newswiremoderation.txt'): # show the edit icon highlighted - htmlStr += \ + html_str += \ ' ' + \ - '' + \
                 translate['Edit newswire'] + ' | \n' else: # show the edit icon - htmlStr += \ + html_str += \ ' ' + \ - '' + \
                 translate['Edit newswire'] + ' | \n' # show the RSS icons - rssIconStr = \ + rss_icon_str = \ ' ' + \ - '' + \
         translate['Hashtag Categories RSS Feed'] + ' | \n' - rssIconStr += \ + rss_icon_str += \ ' ' + \ - '' + \
         translate['Newswire RSS Feed'] + ' | \n' if rss_icon_at_top: - htmlStr += rssIconStr + html_str += rss_icon_str # show publish icon at top - if showPublishButton: + if show_publish_button: if show_publish_as_icon: - titleStr = translate['Publish a blog article'] + title_str = translate['Publish a blog article'] if default_timeline == 'tlfeatures': - titleStr = translate['Publish a news article'] - htmlStr += \ + title_str = translate['Publish a news article'] + html_str += \ ' ' + \ - '' + \
-                titleStr + '\n' - if editImageClass == 'rightColEdit': - htmlStr += '
\n' + if edit_image_class == 'rightColEdit': + html_str += '
\n' else: - if showHeaderImage: - htmlStr += '
\n' + if show_header_image: + html_str += '
\n' - if showPublishButton or editor or rss_icon_at_top: - if not showHeaderImage: - htmlStr += '

' + if show_publish_button or editor or rss_icon_at_top: + if not show_header_image: + html_str += '

' # show the newswire lines - newswireContentStr = \ + newswire_content_str = \ _html_newswire(base_dir, newswire, nickname, moderator, translate, positive_voting) - htmlStr += newswireContentStr + html_str += newswire_content_str # show the rss icon at the bottom, typically on the right hand side - if newswireContentStr and not rss_icon_at_top: - htmlStr += '
' + rssIconStr + '
' - return htmlStr + if newswire_content_str and not rss_icon_at_top: + html_str += '
' + rss_icon_str + '
' + return html_str def _get_broken_fav_substitute() -> str: @@ -218,9 +218,9 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool, translate: {}, positive_voting: bool) -> str: """Converts a newswire dict into html """ - separatorStr = html_post_separator(base_dir, 'right') - htmlStr = '' - for dateStr, item in newswire.items(): + separator_str = html_post_separator(base_dir, 'right') + html_str = '' + for date_str, item in newswire.items(): item[0] = remove_html(item[0]).strip() if not item[0]: continue @@ -230,134 +230,134 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool, if ']' in item[0]: item[0] = item[0].split(']')[0] try: - publishedDate = \ - datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z") + published_date = \ + datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S%z") except BaseException: - print('EX: _html_newswire bad date format ' + dateStr) + print('EX: _html_newswire bad date format ' + date_str) continue - dateShown = publishedDate.strftime("%Y-%m-%d %H:%M") + date_shown = published_date.strftime("%Y-%m-%d %H:%M") - dateStrLink = dateStr.replace('T', ' ') - dateStrLink = dateStrLink.replace('Z', '') + date_str_link = date_str.replace('T', ' ') + date_str_link = date_str_link.replace('Z', '') url = item[1] - faviconUrl = get_newswire_favicon_url(url) - faviconLink = '' - if faviconUrl: - cachedFaviconFilename = \ - get_fav_filename_from_url(base_dir, faviconUrl) - if os.path.isfile(cachedFaviconFilename): - faviconUrl = \ - cachedFaviconFilename.replace(base_dir, '') + favicon_url = get_newswire_favicon_url(url) + favicon_link = '' + if favicon_url: + cached_favicon_filename = \ + get_fav_filename_from_url(base_dir, favicon_url) + if os.path.isfile(cached_favicon_filename): + favicon_url = \ + cached_favicon_filename.replace(base_dir, '') else: extensions = ('png', 'jpg', 'gif', 'avif', 'svg', 'webp') for ext in extensions: - cachedFaviconFilename = \ - get_fav_filename_from_url(base_dir, faviconUrl) - cachedFaviconFilename = \ - cachedFaviconFilename.replace('.ico', '.' + ext) - if os.path.isfile(cachedFaviconFilename): - faviconUrl = \ - cachedFaviconFilename.replace(base_dir, '') + cached_favicon_filename = \ + get_fav_filename_from_url(base_dir, favicon_url) + cached_favicon_filename = \ + cached_favicon_filename.replace('.ico', '.' + ext) + if os.path.isfile(cached_favicon_filename): + favicon_url = \ + cached_favicon_filename.replace(base_dir, '') - faviconLink = \ - '' - moderatedItem = item[5] - htmlStr += separatorStr - if moderatedItem and 'vote:' + nickname in item[2]: - totalVotesStr = '' - totalVotes = 0 + moderated_item = item[5] + html_str += separator_str + if moderated_item and 'vote:' + nickname in item[2]: + total_votes_str = '' + total_votes = 0 if moderator: - totalVotes = votes_on_newswire_item(item[2]) - totalVotesStr = \ - _votes_indicator(totalVotes, positive_voting) + total_votes = votes_on_newswire_item(item[2]) + total_votes_str = \ + _votes_indicator(total_votes, positive_voting) title = remove_long_words(item[0], 16, []).replace('\n', '
') title = limit_repeated_words(title, 6) - htmlStr += '

' + \ + html_str += '

' + \ '' + \ '' + \ - faviconLink + title + '' + totalVotesStr + favicon_link + title + '' + total_votes_str if moderator: - htmlStr += \ - ' ' + dateShown + '' - htmlStr += '

\n' else: - htmlStr += ' ' - htmlStr += dateShown + '

\n' + html_str += ' ' + html_str += date_shown + '

\n' else: - totalVotesStr = '' - totalVotes = 0 + total_votes_str = '' + total_votes = 0 if moderator: - if moderatedItem: - totalVotes = votes_on_newswire_item(item[2]) + if moderated_item: + total_votes = votes_on_newswire_item(item[2]) # show a number of ticks or crosses for how many # votes for or against - totalVotesStr = \ - _votes_indicator(totalVotes, positive_voting) + total_votes_str = \ + _votes_indicator(total_votes, positive_voting) title = remove_long_words(item[0], 16, []).replace('\n', '
') title = limit_repeated_words(title, 6) - if moderator and moderatedItem: - htmlStr += '

' + \ + if moderator and moderated_item: + html_str += '

' + \ '' + \ - faviconLink + title + '' + totalVotesStr - htmlStr += ' ' + dateShown - htmlStr += '' + total_votes_str + html_str += ' ' + date_shown + html_str += '' - htmlStr += '' - htmlStr += '

\n' + html_str += '

\n' else: - htmlStr += '

' + \ + html_str += '

' + \ '' + \ - faviconLink + title + '' + totalVotesStr - htmlStr += ' ' - htmlStr += dateShown + '

\n' + favicon_link + title + '' + total_votes_str + html_str += ' ' + html_str += date_shown + '

\n' - if htmlStr: - htmlStr = '\n' - return htmlStr + if html_str: + html_str = '\n' + return html_str def html_citations(base_dir: str, nickname: str, domain: str, http_prefix: str, default_timeline: str, translate: {}, newswire: {}, css_cache: {}, - blogTitle: str, blogContent: str, - blogImageFilename: str, - blogImageAttachmentMediaType: str, - blogImageDescription: str, + blog_title: str, blog_content: str, + blog_image_filename: str, + blog_image_attachment_media_type: str, + blog_image_description: str, theme: str) -> str: """Show the citations screen when creating a blog """ - htmlStr = '' + html_str = '' # create a list of dates for citations # these can then be used to re-select checkboxes later - citationsFilename = \ + citations_filename = \ acct_dir(base_dir, nickname, domain) + '/.citations.txt' - citationsSelected = [] - if os.path.isfile(citationsFilename): - citationsSeparator = '#####' - with open(citationsFilename, 'r') as f: - citations = f.readlines() + citations_selected = [] + if os.path.isfile(citations_filename): + citations_separator = '#####' + with open(citations_filename, 'r') as fp_cit: + citations = fp_cit.readlines() for line in citations: - if citationsSeparator not in line: + if citations_separator not in line: continue - sections = line.strip().split(citationsSeparator) + sections = line.strip().split(citations_separator) if len(sections) != 3: continue - dateStr = sections[0] - citationsSelected.append(dateStr) + date_str = sections[0] + citations_selected.append(date_str) # the css filename css_filename = base_dir + '/epicyon-profile.css' @@ -366,49 +366,49 @@ def html_citations(base_dir: str, nickname: str, domain: str, instance_title = \ get_config_param(base_dir, 'instanceTitle') - htmlStr = \ + html_str = \ html_header_with_external_style(css_filename, instance_title, None) # top banner - banner_file, banner_filename = \ + banner_file, _ = \ get_banner_file(base_dir, nickname, domain, theme) - htmlStr += \ + html_str += \ '\n' - htmlStr += '\n' - htmlStr += \ + html_str += \ '
\n' - htmlStr += '
\n' - htmlStr += translate['Choose newswire items ' + - 'referenced in your article'] + '
' - if blogTitle is None: - blogTitle = '' - htmlStr += \ + html_str += '
\n' + html_str += translate['Choose newswire items ' + + 'referenced in your article'] + '
' + if blog_title is None: + blog_title = '' + html_str += \ ' \n' - if blogContent is None: - blogContent = '' - htmlStr += \ + blog_title + '">\n' + if blog_content is None: + blog_content = '' + html_str += \ ' \n' + blog_content + '">\n' # submit button - htmlStr += \ + html_str += \ ' \n' - htmlStr += '
\n' + html_str += '
\n' - citationsSeparator = '#####' + citations_separator = '#####' # list of newswire items if newswire: ctr = 0 - for dateStr, item in newswire.items(): + for date_str, item in newswire.items(): item[0] = remove_html(item[0]).strip() if not item[0]: continue @@ -418,32 +418,32 @@ def html_citations(base_dir: str, nickname: str, domain: str, if ']' in item[0]: item[0] = item[0].split(']')[0] # should this checkbox be selected? - selectedStr = '' - if dateStr in citationsSelected: - selectedStr = ' checked' + selected_str = '' + if date_str in citations_selected: + selected_str = ' checked' - publishedDate = \ - datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z") - dateShown = publishedDate.strftime("%Y-%m-%d %H:%M") + published_date = \ + datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S%z") + date_shown = published_date.strftime("%Y-%m-%d %H:%M") title = remove_long_words(item[0], 16, []).replace('\n', '
') title = limit_repeated_words(title, 6) link = item[1] - citationValue = \ - dateStr + citationsSeparator + \ - title + citationsSeparator + \ + citation_value = \ + date_str + citations_separator + \ + title + citations_separator + \ link - htmlStr += \ + html_str += \ '' + \ + '" value="' + citation_value + '"' + selected_str + '/>' + \ '' + title + ' ' - htmlStr += '' + \ - dateShown + '
\n' + html_str += '' + \ + date_shown + '
\n' ctr += 1 - htmlStr += '
\n' - return htmlStr + html_footer() + html_str += '\n' + return html_str + html_footer() def html_newswire_mobile(css_cache: {}, base_dir: str, nickname: str, @@ -451,7 +451,7 @@ def html_newswire_mobile(css_cache: {}, base_dir: str, nickname: str, http_prefix: str, translate: {}, newswire: {}, positive_voting: bool, - timelinePath: str, + timeline_path: str, show_publish_as_icon: bool, authorized: bool, rss_icon_at_top: bool, @@ -461,7 +461,7 @@ def html_newswire_mobile(css_cache: {}, base_dir: str, nickname: str, access_keys: {}) -> str: """Shows the mobile version of the newswire right column """ - htmlStr = '' + html_str = '' # the css filename css_filename = base_dir + '/epicyon-profile.css' @@ -478,47 +478,47 @@ def html_newswire_mobile(css_cache: {}, base_dir: str, nickname: str, # is the user a site editor? editor = is_editor(base_dir, nickname) - showPublishButton = editor + show_publish_button = editor instance_title = \ get_config_param(base_dir, 'instanceTitle') - htmlStr = \ + html_str = \ html_header_with_external_style(css_filename, instance_title, None) - banner_file, banner_filename = \ + banner_file, _ = \ get_banner_file(base_dir, nickname, domain, theme) - htmlStr += \ + html_str += \ '' + \ '\n' - htmlStr += '
\n' + html_str += '
\n' - htmlStr += '
' + \ + html_str += '
' + \ header_buttons_front_screen(translate, nickname, 'newswire', authorized, icons_as_buttons) + '
' - htmlStr += \ + html_str += \ get_right_column_content(base_dir, nickname, domain_full, http_prefix, translate, moderator, editor, newswire, positive_voting, - False, timelinePath, showPublishButton, + False, timeline_path, show_publish_button, show_publish_as_icon, rss_icon_at_top, False, authorized, False, theme, default_timeline, access_keys) if editor and not newswire: - htmlStr += '


\n' - htmlStr += '
\n ' - htmlStr += translate['Select the edit icon to add RSS feeds'] - htmlStr += '\n
\n' + html_str += '


\n' + html_str += '
\n ' + html_str += translate['Select the edit icon to add RSS feeds'] + html_str += '\n
\n' # end of col-right-mobile - htmlStr += '' + html_str += '' - htmlStr += html_footer() - return htmlStr + html_str += html_footer() + return html_str def html_edit_newswire(css_cache: {}, translate: {}, base_dir: str, path: str, @@ -545,115 +545,115 @@ def html_edit_newswire(css_cache: {}, translate: {}, base_dir: str, path: str, css_filename = base_dir + '/links.css' # filename of the banner shown at the top - banner_file, banner_filename = \ + banner_file, _ = \ get_banner_file(base_dir, nickname, domain, theme) instance_title = \ get_config_param(base_dir, 'instanceTitle') - editNewswireForm = \ + edit_newswire_form = \ html_header_with_external_style(css_filename, instance_title, None) # top banner - editNewswireForm += \ + edit_newswire_form += \ '
' + \ '\n' - editNewswireForm += '\n
' - editNewswireForm += \ + edit_newswire_form += \ '
\n' - editNewswireForm += \ + edit_newswire_form += \ '
\n' - editNewswireForm += \ + edit_newswire_form += \ '

' + translate['Edit newswire'] + '

' - editNewswireForm += \ + edit_newswire_form += \ '
\n' - editNewswireForm += \ + edit_newswire_form += \ ' \n' - editNewswireForm += \ + edit_newswire_form += \ '
\n' - newswireFilename = base_dir + '/accounts/newswire.txt' - newswireStr = '' - if os.path.isfile(newswireFilename): - with open(newswireFilename, 'r') as fp: - newswireStr = fp.read() + newswire_filename = base_dir + '/accounts/newswire.txt' + newswire_str = '' + if os.path.isfile(newswire_filename): + with open(newswire_filename, 'r') as fp_news: + newswire_str = fp_news.read() - editNewswireForm += \ + edit_newswire_form += \ '
' - editNewswireForm += \ + edit_newswire_form += \ ' ' + \ translate['Add RSS feed links below.'] + \ '
' - newFeedStr = translate['New feed URL'] - editNewswireForm += \ - edit_text_field(None, 'newNewswireFeed', '', newFeedStr) - editNewswireForm += \ + new_feed_str = translate['New feed URL'] + edit_newswire_form += \ + edit_text_field(None, 'newNewswireFeed', '', new_feed_str) + edit_newswire_form += \ ' ' + newswire_str + '' - filterStr = '' - filterFilename = \ + filter_str = '' + filter_filename = \ base_dir + '/accounts/news@' + domain + '/filters.txt' - if os.path.isfile(filterFilename): - with open(filterFilename, 'r') as filterfile: - filterStr = filterfile.read() + if os.path.isfile(filter_filename): + with open(filter_filename, 'r') as filterfile: + filter_str = filterfile.read() - editNewswireForm += \ + edit_newswire_form += \ '
\n' - editNewswireForm += '
' - editNewswireForm += html_footer() - return editNewswireForm + edit_newswire_form += html_footer() + return edit_newswire_form def html_edit_news_post(css_cache: {}, translate: {}, base_dir: str, path: str, - domain: str, port: int, - http_prefix: str, postUrl: str, + domain: str, port: int, http_prefix: str, postUrl: str, system_language: str) -> str: """Edits a news post on the news/features timeline """ if '/users/' not in path: return '' - pathOriginal = path + path_original = path nickname = get_nickname_from_actor(path) if not nickname: @@ -677,47 +677,47 @@ def html_edit_news_post(css_cache: {}, translate: {}, base_dir: str, path: str, instance_title = \ get_config_param(base_dir, 'instanceTitle') - editNewsPostForm = \ + edit_news_post_form = \ html_header_with_external_style(css_filename, instance_title, None) - editNewsPostForm += \ + edit_news_post_form += \ '\n' - editNewsPostForm += \ + edit_news_post_form += \ '
\n' - editNewsPostForm += \ + edit_news_post_form += \ '

' + translate['Edit News Post'] + '

' - editNewsPostForm += \ + edit_news_post_form += \ '
\n' - editNewsPostForm += \ - ' ' + \ + edit_news_post_form += \ + ' ' + \ '\n' - editNewsPostForm += \ + edit_news_post_form += \ ' \n' - editNewsPostForm += \ + edit_news_post_form += \ '
\n' - editNewsPostForm += \ + edit_news_post_form += \ '
' - editNewsPostForm += \ + edit_news_post_form += \ ' \n' - newsPostTitle = post_json_object['object']['summary'] - editNewsPostForm += \ + news_post_title = post_json_object['object']['summary'] + edit_news_post_form += \ '
\n' + news_post_title + '">
\n' - newsPostContent = get_base_content_from_post(post_json_object, - system_language) - editNewsPostForm += \ + news_post_content = get_base_content_from_post(post_json_object, + system_language) + edit_news_post_form += \ ' ' + news_post_content + '' - editNewsPostForm += \ + edit_news_post_form += \ '
' - editNewsPostForm += html_footer() - return editNewsPostForm + edit_news_post_form += html_footer() + return edit_news_post_form