forked from indymedia/epicyon
Show vote results
parent
d41187620e
commit
e2a9814ef9
|
@ -184,12 +184,12 @@ def readFollowList(filename: str) -> None:
|
||||||
class PubServer(BaseHTTPRequestHandler):
|
class PubServer(BaseHTTPRequestHandler):
|
||||||
protocol_version = 'HTTP/1.1'
|
protocol_version = 'HTTP/1.1'
|
||||||
|
|
||||||
def _sendVote(self,nickname: str,messageId: str,answer: str) -> None:
|
def _sendReplyToQuestion(self,nickname: str,messageId: str,answer: str) -> None:
|
||||||
"""Sends a vote
|
"""Sends a reply to a question
|
||||||
"""
|
"""
|
||||||
votesFilename= \
|
votesFilename= \
|
||||||
self.server.baseDir+'/accounts/'+ \
|
self.server.baseDir+'/accounts/'+ \
|
||||||
nickname+'@'+self.server.domain+'/votes.txt'
|
nickname+'@'+self.server.domain+'/questions.txt'
|
||||||
|
|
||||||
# have we already voted on this?
|
# have we already voted on this?
|
||||||
if messageId in open(votesFilename).read():
|
if messageId in open(votesFilename).read():
|
||||||
|
@ -4277,7 +4277,7 @@ 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]
|
||||||
self._sendVote(nickname,messageId,answer)
|
self._sendReplyToQuestion(nickname,messageId,answer)
|
||||||
self._redirect_headers(actor+'/inbox?page='+str(pageNumber),cookie)
|
self._redirect_headers(actor+'/inbox?page='+str(pageNumber),cookie)
|
||||||
self.server.POSTbusy=False
|
self.server.POSTbusy=False
|
||||||
return
|
return
|
||||||
|
|
|
@ -780,6 +780,9 @@ div.gallery img {
|
||||||
.question {
|
.question {
|
||||||
font-size: var(--font-size);
|
font-size: var(--font-size);
|
||||||
}
|
}
|
||||||
|
.questionresult {
|
||||||
|
font-size: var(--font-size);
|
||||||
|
}
|
||||||
input[type=radio] {
|
input[type=radio] {
|
||||||
font-size: var(--font-size);
|
font-size: var(--font-size);
|
||||||
width: 32px;
|
width: 32px;
|
||||||
|
@ -1065,6 +1068,9 @@ div.gallery img {
|
||||||
.question {
|
.question {
|
||||||
font-size: var(--font-size3);
|
font-size: var(--font-size3);
|
||||||
}
|
}
|
||||||
|
.questionresult {
|
||||||
|
font-size: var(--font-size3);
|
||||||
|
}
|
||||||
input[type=radio] {
|
input[type=radio] {
|
||||||
font-size: var(--font-size3);
|
font-size: var(--font-size3);
|
||||||
height: 90px;
|
height: 90px;
|
||||||
|
|
|
@ -1755,7 +1755,7 @@ def followerApprovalActive(baseDir: str,nickname: str,domain: str) -> bool:
|
||||||
manuallyApprovesFollowers=actorJson['manuallyApprovesFollowers']
|
manuallyApprovesFollowers=actorJson['manuallyApprovesFollowers']
|
||||||
return manuallyApprovesFollowers
|
return manuallyApprovesFollowers
|
||||||
|
|
||||||
def insertQuestion(translate: {}, \
|
def insertQuestion(baseDir: str,translate: {}, \
|
||||||
nickname: str,domain: str,port: int, \
|
nickname: str,domain: str,port: int, \
|
||||||
content: str, \
|
content: str, \
|
||||||
postJsonObject: {},pageNumber: int) -> str:
|
postJsonObject: {},pageNumber: int) -> str:
|
||||||
|
@ -1771,6 +1771,12 @@ def insertQuestion(translate: {}, \
|
||||||
pageNumberStr=''
|
pageNumberStr=''
|
||||||
if pageNumber:
|
if pageNumber:
|
||||||
pageNumberStr='?page='+str(pageNumber)
|
pageNumberStr='?page='+str(pageNumber)
|
||||||
|
|
||||||
|
votesFilename= \
|
||||||
|
baseDir+'/accounts/'+nickname+'@'+domain+'/questions.txt'
|
||||||
|
|
||||||
|
if messageId not in open(votesFilename).read():
|
||||||
|
# show the question options
|
||||||
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="'+messageId+'"><br>'
|
content+='<input type="hidden" name="messageId" value="'+messageId+'"><br>'
|
||||||
|
@ -1782,6 +1788,38 @@ def insertQuestion(translate: {}, \
|
||||||
content+='<input type="radio" name="answer" value="'+choice['name']+'"> '+choice['name']+'<br><br>'
|
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+='<input type="submit" value="'+translate['Vote']+'" class="vote"><br><br>'
|
||||||
content+='</form></div>'
|
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
|
return content
|
||||||
|
|
||||||
def addEmojiToDisplayName(baseDir: str,httpPrefix: str, \
|
def addEmojiToDisplayName(baseDir: str,httpPrefix: str, \
|
||||||
|
@ -2334,7 +2372,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \
|
||||||
if not postJsonObject['object']['sensitive']:
|
if not postJsonObject['object']['sensitive']:
|
||||||
contentStr=objectContent+attachmentStr
|
contentStr=objectContent+attachmentStr
|
||||||
contentStr=addEmbeddedElements(translate,contentStr)
|
contentStr=addEmbeddedElements(translate,contentStr)
|
||||||
contentStr=insertQuestion(translate,nickname,domain,port, \
|
contentStr=insertQuestion(baseDir,translate,nickname,domain,port, \
|
||||||
contentStr,postJsonObject,pageNumber)
|
contentStr,postJsonObject,pageNumber)
|
||||||
else:
|
else:
|
||||||
postID='post'+str(createPassword(8))
|
postID='post'+str(createPassword(8))
|
||||||
|
@ -2347,7 +2385,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \
|
||||||
contentStr+='<div class="cwText" id="'+postID+'">'
|
contentStr+='<div class="cwText" id="'+postID+'">'
|
||||||
contentStr+=objectContent+attachmentStr
|
contentStr+=objectContent+attachmentStr
|
||||||
contentStr=addEmbeddedElements(translate,contentStr)
|
contentStr=addEmbeddedElements(translate,contentStr)
|
||||||
contentStr=insertQuestion(translate,nickname,domain,port, \
|
contentStr=insertQuestion(baseDir,translate,nickname,domain,port, \
|
||||||
contentStr,postJsonObject,pageNumber)
|
contentStr,postJsonObject,pageNumber)
|
||||||
contentStr+='</div>'
|
contentStr+='</div>'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue