From adc6cd93176cd5b728db413757411367528a38f1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Oct 2020 20:46:22 +0100 Subject: [PATCH] Show total moderator votes on newswire items --- newswire.py | 5 ++--- webinterface.py | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/newswire.py b/newswire.py index 6418560c..1c1aee15 100644 --- a/newswire.py +++ b/newswire.py @@ -79,7 +79,7 @@ def xml2StrToDict(xmlStr: str) -> {}: try: publishedDate = \ datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S %z") - result[str(publishedDate)] = [title, link, ['votes:0']] + result[str(publishedDate)] = [title, link, []] parsed = True except BaseException: pass @@ -232,8 +232,7 @@ def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str, published = published.replace('Z', '+00:00') newswire[published] = \ [postJsonObject['object']['summary'], - postJsonObject['object']['url'], - ['votes:0']] + postJsonObject['object']['url'], []] ctr += 1 if ctr >= maxBlogsPerAccount: diff --git a/webinterface.py b/webinterface.py index 8d4eb8c9..4e57e012 100644 --- a/webinterface.py +++ b/webinterface.py @@ -5347,8 +5347,19 @@ def htmlNewswire(newswire: str, nickname: str, moderator: bool) -> str: dateStrLink = dateStr.replace(' ', 'T') dateStrLink = dateStrLink.replace('+00:00', '') if 'vote:' + nickname in item[2]: + totalVotesStr = '' + if moderator: + # count the total votes for this item + totalVotes = 0 + for line in item[2]: + if '[vote:' in line: + totalVotes += 1 + if totalVotes > 0: + totalVotesStr = ' +' + str(totalVotes) + htmlStr += '

' + \ - '' + item[0] + '' + '' + item[0] + '' + \ + totalVotesStr if moderator: htmlStr += \ ' ' + \ @@ -5360,8 +5371,19 @@ def htmlNewswire(newswire: str, nickname: str, moderator: bool) -> str: htmlStr += '

' else: + totalVotesStr = '' + if moderator: + # count the total votes for this item + totalVotes = 0 + for line in item[2]: + if '[vote:' in line: + totalVotes += 1 + if totalVotes > 0: + totalVotesStr = ' +' + str(totalVotes) + htmlStr += '

' + \ - '' + item[0] + '' + '' + item[0] + '' + \ + totalVotesStr if moderator: htmlStr += \ ' ' + \