forked from indymedia/epicyon
Show vote results
parent
d41187620e
commit
e2a9814ef9
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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+='<div class="question">'
|
||||
content+='<form method="POST" action="/users/'+nickname+'/question'+pageNumberStr+'">'
|
||||
content+='<input type="hidden" name="messageId" value="'+messageId+'"><br>'
|
||||
for choice in postJsonObject['object']['oneOf']:
|
||||
if not choice.get('type'):
|
||||
continue
|
||||
if not choice.get('name'):
|
||||
continue
|
||||
content+='<input type="radio" name="answer" value="'+choice['name']+'"> '+choice['name']+'<br><br>'
|
||||
content+='<input type="submit" value="'+translate['Vote']+'" class="vote"><br><br>'
|
||||
content+='</form></div>'
|
||||
|
||||
votesFilename= \
|
||||
baseDir+'/accounts/'+nickname+'@'+domain+'/questions.txt'
|
||||
|
||||
if messageId not in open(votesFilename).read():
|
||||
# show the question options
|
||||
content+='<div class="question">'
|
||||
content+='<form method="POST" action="/users/'+nickname+'/question'+pageNumberStr+'">'
|
||||
content+='<input type="hidden" name="messageId" value="'+messageId+'"><br>'
|
||||
for choice in postJsonObject['object']['oneOf']:
|
||||
if not choice.get('type'):
|
||||
continue
|
||||
if not choice.get('name'):
|
||||
continue
|
||||
content+='<input type="radio" name="answer" value="'+choice['name']+'"> '+choice['name']+'<br><br>'
|
||||
content+='<input type="submit" value="'+translate['Vote']+'" class="vote"><br><br>'
|
||||
content+='</form></div>'
|
||||
else:
|
||||
# show the responses to a question
|
||||
content+='<div class="questionresult">'
|
||||
|
||||
# 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+='<p><input type="text" placeholder="" title="'+str(votes)+'" name="skillName'+str(questionCtr)+'" value="'+questionOption['name']+'" style="width:40%">'
|
||||
content+='<input type="range" min="1" max="100" class="slider" title="'+str(votes)+'" name="skillValue'+str(questionCtr)+'" value="'+votesPercent+'"></p>'
|
||||
questionCtr+=1
|
||||
content+='</div>'
|
||||
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+='<div class="cwText" id="'+postID+'">'
|
||||
contentStr+=objectContent+attachmentStr
|
||||
contentStr=addEmbeddedElements(translate,contentStr)
|
||||
contentStr=insertQuestion(translate,nickname,domain,port, \
|
||||
contentStr=insertQuestion(baseDir,translate,nickname,domain,port, \
|
||||
contentStr,postJsonObject,pageNumber)
|
||||
contentStr+='</div>'
|
||||
|
||||
|
|
Loading…
Reference in New Issue