Keep track of votes

main
Bob Mottram 2019-11-25 12:33:05 +00:00
parent 4ed9020883
commit 71fb0285b3
2 changed files with 16 additions and 1 deletions

View File

@ -4235,6 +4235,13 @@ class PubServer(BaseHTTPRequestHandler):
answer=questionParams.split('answer=')[1] answer=questionParams.split('answer=')[1]
if '&' in answer: if '&' in answer:
answer=answer.split('&')[0] answer=answer.split('&')[0]
votesFilename=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/votes.txt'
# have we already voted on this?
if messageId in open(votesFilename).read():
print('Already voted on message '+messageId)
self._redirect_headers(actor+'/inbox?page='+str(pageNumber),cookie)
self.server.POSTbusy=False
return
print('Voting on message '+messageId) print('Voting on message '+messageId)
print('Vote for: '+answer) print('Vote for: '+answer)
messageJson= \ messageJson= \
@ -4255,6 +4262,11 @@ class PubServer(BaseHTTPRequestHandler):
messageJson, \ messageJson, \
self.server.maxReplies, \ self.server.maxReplies, \
self.server.debug) self.server.debug)
# record the vote
votesFile=open(votesFilename,'a+')
if votesFile:
votesFile.write(messageId+'\n')
votesFile.close()
else: else:
print('ERROR: unable to post vote to outbox') print('ERROR: unable to post vote to outbox')
else: else:

View File

@ -1765,12 +1765,15 @@ def insertQuestion(translate: {}, \
return content return content
if len(postJsonObject['object']['oneOf'])==0: if len(postJsonObject['object']['oneOf'])==0:
return content return content
messageId=postJsonObject['id'].replace('/activity','')
if '#' in messageId:
messageId=messageId.split('#',1)[0]
pageNumberStr='' pageNumberStr=''
if pageNumber: if pageNumber:
pageNumberStr='?page='+str(pageNumber) pageNumberStr='?page='+str(pageNumber)
content+='<div class="question">' content+='<div class="question">'
content+='<form method="POST" action="/users/'+nickname+'/question'+pageNumberStr+'">' content+='<form method="POST" action="/users/'+nickname+'/question'+pageNumberStr+'">'
content+='<input type="hidden" name="messageId" value="'+postJsonObject['id']+'"><br>' content+='<input type="hidden" name="messageId" value="'+messageId+'"><br>'
for choice in postJsonObject['object']['oneOf']: for choice in postJsonObject['object']['oneOf']:
if not choice.get('type'): if not choice.get('type'):
continue continue