Handle citations differently, because mime decoding an array doesn't look feasible

main
Bob Mottram 2020-11-06 10:05:14 +00:00
parent 2f1664597d
commit f04cbd0e21
2 changed files with 21 additions and 10 deletions

View File

@ -3053,13 +3053,15 @@ class PubServer(BaseHTTPRequestHandler):
baseDir: str, httpPrefix: str, baseDir: str, httpPrefix: str,
domain: str, domainFull: str, domain: str, domainFull: str,
onionDomain: str, i2pDomain: str, debug: bool, onionDomain: str, i2pDomain: str, debug: bool,
defaultTimeline: str) -> None: defaultTimeline: str,
newswire: {}) -> None:
"""Updates the citations for a blog post after hitting """Updates the citations for a blog post after hitting
update button on the citations screen update button on the citations screen
""" """
usersPath = path.replace('/citationsdata', '') usersPath = path.replace('/citationsdata', '')
actorStr = httpPrefix + '://' + domainFull + usersPath 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] boundary = self.headers['Content-type'].split('boundary=')[1]
if ';' in boundary: if ';' in boundary:
boundary = boundary.split(';')[0] boundary = boundary.split(';')[0]
@ -3111,14 +3113,20 @@ class PubServer(BaseHTTPRequestHandler):
# extract all of the text fields into a dict # extract all of the text fields into a dict
fields = \ fields = \
extractTextFieldsInPOST(postBytes, boundary, debug) extractTextFieldsInPOST(postBytes, boundary, debug)
print('citationstest: ' + str(fields)) citations = []
if fields.get('citations'): for dateStr, item in newswire.items():
if fields.get(dateStr):
if fields[dateStr] == 'on':
citations.append(dateStr)
if citations:
citationsFilename = \ citationsFilename = \
baseDir + '/accounts/' + \ baseDir + '/accounts/' + \
nickname + '@' + domain + '/.citations.txt' nickname + '@' + domain + '/.citations.txt'
citationsStr = fields['citations'] citationsStr = ''
print('DEBUG: citationsStr = ' + citationsStr) for citationDate in citations:
# save citations, so that they can be added when citationsStr += citationDate + '\n'
# save citations dates, so that they can be added when
# reloading the newblog screen # reloading the newblog screen
citationsFile = open(citationsFilename, "w+") citationsFile = open(citationsFilename, "w+")
if citationsFile: if citationsFile:
@ -11773,7 +11781,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domainFull, self.server.domainFull,
self.server.onionDomain, self.server.onionDomain,
self.server.i2pDomain, self.server.debug, self.server.i2pDomain, self.server.debug,
self.server.defaultTimeline) self.server.defaultTimeline,
self.server.newswire)
return return
if authorized and self.path.endswith('/newseditdata'): if authorized and self.path.endswith('/newseditdata'):

View File

@ -5914,6 +5914,7 @@ def htmlCitations(baseDir: str, nickname: str, domain: str,
# list of newswire items # list of newswire items
if newswire: if newswire:
ctr = 0
for dateStr, item in newswire.items(): for dateStr, item in newswire.items():
publishedDate = \ publishedDate = \
datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z") 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] link = item[1]
htmlStr += \ htmlStr += \
'<input type="checkbox" name="citations[]" ' + \ '<input type="checkbox" name="' + dateStr + \
'value="' + dateStr + '"/>' + \ '" value="' + dateStr + '"/>' + \
'<a href="' + link + '">' + title + '</a> ' '<a href="' + link + '">' + title + '</a> '
htmlStr += '<span class="newswireDate">' + \ htmlStr += '<span class="newswireDate">' + \
dateShown + '</span><br>\n' dateShown + '</span><br>\n'
ctr += 1
htmlStr += '</form>\n' htmlStr += '</form>\n'
return htmlStr + htmlFooter() return htmlStr + htmlFooter()