From f04cbd0e214e153748df677851fba09c2be3bb0d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 6 Nov 2020 10:05:14 +0000 Subject: [PATCH] Handle citations differently, because mime decoding an array doesn't look feasible --- daemon.py | 25 +++++++++++++++++-------- webinterface.py | 6 ++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/daemon.py b/daemon.py index 9c10b9da6..abe2dd6fa 100644 --- a/daemon.py +++ b/daemon.py @@ -3053,13 +3053,15 @@ class PubServer(BaseHTTPRequestHandler): baseDir: str, httpPrefix: str, domain: str, domainFull: str, onionDomain: str, i2pDomain: str, debug: bool, - defaultTimeline: str) -> None: + defaultTimeline: str, + newswire: {}) -> None: """Updates the citations for a blog post after hitting update button on the citations screen """ usersPath = path.replace('/citationsdata', '') actorStr = httpPrefix + '://' + domainFull + usersPath - if ' boundary=' in self.headers['Content-type']: + if newswire and \ + ' boundary=' in self.headers['Content-type']: boundary = self.headers['Content-type'].split('boundary=')[1] if ';' in boundary: boundary = boundary.split(';')[0] @@ -3111,14 +3113,20 @@ class PubServer(BaseHTTPRequestHandler): # extract all of the text fields into a dict fields = \ extractTextFieldsInPOST(postBytes, boundary, debug) - print('citationstest: ' + str(fields)) - if fields.get('citations'): + citations = [] + for dateStr, item in newswire.items(): + if fields.get(dateStr): + if fields[dateStr] == 'on': + citations.append(dateStr) + + if citations: citationsFilename = \ baseDir + '/accounts/' + \ nickname + '@' + domain + '/.citations.txt' - citationsStr = fields['citations'] - print('DEBUG: citationsStr = ' + citationsStr) - # save citations, so that they can be added when + citationsStr = '' + for citationDate in citations: + citationsStr += citationDate + '\n' + # save citations dates, so that they can be added when # reloading the newblog screen citationsFile = open(citationsFilename, "w+") if citationsFile: @@ -11773,7 +11781,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.domainFull, self.server.onionDomain, self.server.i2pDomain, self.server.debug, - self.server.defaultTimeline) + self.server.defaultTimeline, + self.server.newswire) return if authorized and self.path.endswith('/newseditdata'): diff --git a/webinterface.py b/webinterface.py index e2992d69c..1cd4b94ca 100644 --- a/webinterface.py +++ b/webinterface.py @@ -5914,6 +5914,7 @@ def htmlCitations(baseDir: str, nickname: str, domain: str, # list of newswire items if newswire: + ctr = 0 for dateStr, item in newswire.items(): publishedDate = \ datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z") @@ -5923,11 +5924,12 @@ def htmlCitations(baseDir: str, nickname: str, domain: str, link = item[1] htmlStr += \ - '' + \ + '' + \ '' + title + ' ' htmlStr += '' + \ dateShown + '
\n' + ctr += 1 htmlStr += '\n' return htmlStr + htmlFooter()