From 95042c3d1dc8bbac624b2fab075078610d226580 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 30 Nov 2020 20:52:58 +0000 Subject: [PATCH] Separate function for citations --- webapp_post.py | 75 +++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/webapp_post.py b/webapp_post.py index b2bf36d3..269995f4 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -602,6 +602,36 @@ def getPublishedDateStr(postJsonObject: {}, return publishedStr +def getBlogCitationsHtml(boxName: str, + postJsonObject: {}, + translate: {}) -> str: + """Returns blog citations as html + """ + # show blog citations + citationsStr = '' + if boxName == 'tlblogs' or boxName == 'tlfeatures': + if postJsonObject['object'].get('tag'): + for tagJson in postJsonObject['object']['tag']: + if not isinstance(tagJson, dict): + continue + if not tagJson.get('type'): + continue + if tagJson['type'] != 'Article': + continue + if not tagJson.get('name'): + continue + if not tagJson.get('url'): + continue + citationsStr += \ + '
  • ' + \ + '' + tagJson['name'] + '
  • \n' + if citationsStr: + citationsStr = '

    ' + translate['Citations'] + \ + ':

    ' + \ + '\n' + return citationsStr + + def individualPostAsHtml(allowDownloads: bool, recentPostsCache: {}, maxRecentPosts: int, iconsPath: str, translate: {}, @@ -873,16 +903,17 @@ def individualPostAsHtml(allowDownloads: bool, editStr = getEditIconHtml(baseDir, nickname, domainFull, postJsonObject, actorNickname, translate, iconsPath, isEvent) - - announceStr = getAnnounceIconHtml(nickname, domainFull, - postJsonObject, - isPublicRepeat, - isModerationPost, - showRepeatIcon, - translate, - pageNumberParam, - timelinePostBookmark, - boxName, iconsPath) + + announceStr = \ + getAnnounceIconHtml(nickname, domainFull, + postJsonObject, + isPublicRepeat, + isModerationPost, + showRepeatIcon, + translate, + pageNumberParam, + timelinePostBookmark, + boxName, iconsPath) # benchmark 12 if enableTimingLog: @@ -1426,27 +1457,8 @@ def individualPostAsHtml(allowDownloads: bool, '\n' # show blog citations - citationsStr = '' - if boxName == 'tlblogs' or boxName == 'tlfeatures': - if postJsonObject['object'].get('tag'): - for tagJson in postJsonObject['object']['tag']: - if not isinstance(tagJson, dict): - continue - if not tagJson.get('type'): - continue - if tagJson['type'] != 'Article': - continue - if not tagJson.get('name'): - continue - if not tagJson.get('url'): - continue - citationsStr += \ - '
  • ' + \ - '' + tagJson['name'] + '
  • \n' - if citationsStr: - citationsStr = '

    ' + translate['Citations'] + \ - ':

    ' + \ - '\n' + citationsStr = \ + getBlogCitationsHtml(boxName, postJsonObject, translate) postHtml = '' if boxName != 'tlmedia': @@ -1467,6 +1479,7 @@ def individualPostAsHtml(allowDownloads: bool, if timeDiff > 100: print('TIMING INDIV ' + boxName + ' 18 = ' + str(timeDiff)) + # save the created html to the recent posts cache if not showPublicOnly and storeToCache and \ boxName != 'tlmedia' and boxName != 'tlbookmarks' and \ boxName != 'bookmarks':