diff --git a/daemon.py b/daemon.py index c1af2b1d..9dc113b4 100644 --- a/daemon.py +++ b/daemon.py @@ -184,12 +184,12 @@ def readFollowList(filename: str) -> None: class PubServer(BaseHTTPRequestHandler): protocol_version = 'HTTP/1.1' - def _sendVote(self,nickname: str,messageId: str,answer: str) -> None: - """Sends a vote + def _sendReplyToQuestion(self,nickname: str,messageId: str,answer: str) -> None: + """Sends a reply to a question """ votesFilename= \ self.server.baseDir+'/accounts/'+ \ - nickname+'@'+self.server.domain+'/votes.txt' + nickname+'@'+self.server.domain+'/questions.txt' # have we already voted on this? if messageId in open(votesFilename).read(): @@ -4277,7 +4277,7 @@ class PubServer(BaseHTTPRequestHandler): answer=questionParams.split('answer=')[1] if '&' in answer: answer=answer.split('&')[0] - self._sendVote(nickname,messageId,answer) + self._sendReplyToQuestion(nickname,messageId,answer) self._redirect_headers(actor+'/inbox?page='+str(pageNumber),cookie) self.server.POSTbusy=False return diff --git a/epicyon-profile.css b/epicyon-profile.css index ad9a48fc..9d49f1fe 100644 --- a/epicyon-profile.css +++ b/epicyon-profile.css @@ -780,6 +780,9 @@ div.gallery img { .question { font-size: var(--font-size); } + .questionresult { + font-size: var(--font-size); + } input[type=radio] { font-size: var(--font-size); width: 32px; @@ -1065,6 +1068,9 @@ div.gallery img { .question { font-size: var(--font-size3); } + .questionresult { + font-size: var(--font-size3); + } input[type=radio] { font-size: var(--font-size3); height: 90px; diff --git a/webinterface.py b/webinterface.py index ae584724..cffd18b8 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1755,7 +1755,7 @@ def followerApprovalActive(baseDir: str,nickname: str,domain: str) -> bool: manuallyApprovesFollowers=actorJson['manuallyApprovesFollowers'] return manuallyApprovesFollowers -def insertQuestion(translate: {}, \ +def insertQuestion(baseDir: str,translate: {}, \ nickname: str,domain: str,port: int, \ content: str, \ postJsonObject: {},pageNumber: int) -> str: @@ -1771,17 +1771,55 @@ def insertQuestion(translate: {}, \ pageNumberStr='' if pageNumber: pageNumberStr='?page='+str(pageNumber) - content+='
' - content+='
' - content+='
' - for choice in postJsonObject['object']['oneOf']: - if not choice.get('type'): - continue - if not choice.get('name'): - continue - content+=' '+choice['name']+'

' - content+='

' - content+='
' + + votesFilename= \ + baseDir+'/accounts/'+nickname+'@'+domain+'/questions.txt' + + if messageId not in open(votesFilename).read(): + # show the question options + content+='
' + content+='
' + content+='
' + for choice in postJsonObject['object']['oneOf']: + if not choice.get('type'): + continue + if not choice.get('name'): + continue + content+=' '+choice['name']+'

' + content+='

' + content+='
' + else: + # show the responses to a question + content+='
' + + # get the maximum number of votes + maxVotes=1 + for questionOption in postJsonObject['object']['oneOf']: + if not questionOption.get('name'): + continue + if not questionOption.get('replies'): + continue + if not questionOption['replies'].get('totalItems'): + continue + votes=int(questionOption['replies']['totalItems']) + if votes>maxVotes: + maxVotes=int(votes+1) + + # show the votes as sliders + questionCtr=1 + for questionOption in postJsonObject['object']['oneOf']: + if not questionOption.get('name'): + continue + if not questionOption.get('replies'): + continue + if not questionOption['replies'].get('totalItems'): + continue + votes=int(questionOption['replies']['totalItems']) + votesPercent=str(int(votes*100/maxVotes)) + content+='

' + content+='

' + questionCtr+=1 + content+='
' return content def addEmojiToDisplayName(baseDir: str,httpPrefix: str, \ @@ -2334,7 +2372,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \ if not postJsonObject['object']['sensitive']: contentStr=objectContent+attachmentStr contentStr=addEmbeddedElements(translate,contentStr) - contentStr=insertQuestion(translate,nickname,domain,port, \ + contentStr=insertQuestion(baseDir,translate,nickname,domain,port, \ contentStr,postJsonObject,pageNumber) else: postID='post'+str(createPassword(8)) @@ -2347,7 +2385,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \ contentStr+='
' contentStr+=objectContent+attachmentStr contentStr=addEmbeddedElements(translate,contentStr) - contentStr=insertQuestion(translate,nickname,domain,port, \ + contentStr=insertQuestion(baseDir,translate,nickname,domain,port, \ contentStr,postJsonObject,pageNumber) contentStr+='
'