mirror of https://gitlab.com/bashrc2/epicyon
Displaying questions
parent
ec66ac56a8
commit
8997b77277
|
@ -482,6 +482,17 @@ a:link {
|
|||
background-color: #999;
|
||||
}
|
||||
|
||||
.question {
|
||||
font-size: var(--font-size);
|
||||
}
|
||||
|
||||
input[type=radio] {
|
||||
width: 32px;
|
||||
margin : 0;
|
||||
padding : 0;
|
||||
opacity : 0;
|
||||
}
|
||||
|
||||
input[type=text], select, textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
|
|
3
posts.py
3
posts.py
|
@ -1803,7 +1803,8 @@ def createBoxBase(baseDir: str,boxname: str, \
|
|||
# must be a "Note" or "Announce" type
|
||||
with open(filePath, 'r') as file:
|
||||
postStr = file.read()
|
||||
if '"Note"' in postStr or '"Announce"' in postStr:
|
||||
if '"Note"' in postStr or '"Announce"' in postStr or \
|
||||
('"Question"' in postStr and '"Create"' in postStr):
|
||||
isPost=True
|
||||
if boxname=='dm':
|
||||
if '#Public' in postStr or '/followers' in postStr:
|
||||
|
|
|
@ -1374,6 +1374,26 @@ def followerApprovalActive(baseDir: str,nickname: str,domain: str) -> bool:
|
|||
manuallyApprovesFollowers=actorJson['manuallyApprovesFollowers']
|
||||
return manuallyApprovesFollowers
|
||||
|
||||
def insertQuestion(nickname: str,content: str,postJsonObject: {}) -> str:
|
||||
""" Inserts question selection into a post
|
||||
"""
|
||||
if not isQuestion(postJsonObject):
|
||||
return content
|
||||
if len(postJsonObject['object']['oneOf'])==0:
|
||||
return content
|
||||
content+='<div class="question">'
|
||||
content+='<form method="POST" action="/users/'+nickname+'/question">'
|
||||
content+='<input type="hidden" name="messageId" value="'+postJsonObject['id']+'">'
|
||||
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>'
|
||||
content+='<input type="submit" value="Submit">'
|
||||
content+='</form></div>'
|
||||
return content
|
||||
|
||||
def individualPostAsHtml(pageNumber: int,baseDir: str, \
|
||||
session,wfRequest: {},personCache: {}, \
|
||||
nickname: str,domain: str,port: int, \
|
||||
|
@ -1705,6 +1725,7 @@ def individualPostAsHtml(pageNumber: int,baseDir: str, \
|
|||
if not postJsonObject['object']['sensitive']:
|
||||
contentStr=postJsonObject['object']['content']+attachmentStr
|
||||
contentStr=addEmbeddedElements(contentStr)
|
||||
contentStr=insertQuestion(nickname,contentStr,postJsonObject)
|
||||
else:
|
||||
postID='post'+str(createPassword(8))
|
||||
contentStr=''
|
||||
|
@ -1718,6 +1739,7 @@ def individualPostAsHtml(pageNumber: int,baseDir: str, \
|
|||
contentStr+='<div class="cwText" id="'+postID+'">'
|
||||
contentStr+=postJsonObject['object']['content']+attachmentStr
|
||||
contentStr=addEmbeddedElements(contentStr)
|
||||
contentStr=insertQuestion(nickname,contentStr,postJsonObject)
|
||||
contentStr+='</div>'
|
||||
|
||||
if postJsonObject['object'].get('tag'):
|
||||
|
@ -1732,6 +1754,18 @@ def individualPostAsHtml(pageNumber: int,baseDir: str, \
|
|||
contentStr+footerStr+ \
|
||||
'</div>\n'
|
||||
|
||||
def isQuestion(postObjectJson: {}) -> bool:
|
||||
""" is the given post a question?
|
||||
"""
|
||||
if postObjectJson['type']=='Create':
|
||||
if isinstance(postObjectJson['object'], dict):
|
||||
if postObjectJson['object'].get('type'):
|
||||
if postObjectJson['object']['type']=='Question':
|
||||
if postObjectJson['object'].get('oneOf'):
|
||||
if isinstance(postObjectJson['object']['oneOf'], list):
|
||||
return True
|
||||
return False
|
||||
|
||||
def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
|
||||
wfRequest: {},personCache: {}, \
|
||||
nickname: str,domain: str,port: int,timelineJson: {}, \
|
||||
|
@ -1834,14 +1868,15 @@ def htmlTimeline(pageNumber: int,itemsPerPage: int,session,baseDir: str, \
|
|||
if item['type']=='Create' or item['type']=='Announce':
|
||||
itemCtr+=1
|
||||
avatarUrl=getPersonAvatarUrl(baseDir,item['actor'],personCache)
|
||||
tlStr+=individualPostAsHtml(pageNumber, \
|
||||
baseDir,session,wfRequest,personCache, \
|
||||
nickname,domain,port,item,avatarUrl,True, \
|
||||
allowDeletion, \
|
||||
httpPrefix,projectVersion, \
|
||||
boxName!='dm', \
|
||||
showIndividualPostIcons, \
|
||||
manuallyApproveFollowers,False)
|
||||
tlStr+= \
|
||||
individualPostAsHtml(pageNumber, \
|
||||
baseDir,session,wfRequest,personCache, \
|
||||
nickname,domain,port,item,avatarUrl,True, \
|
||||
allowDeletion, \
|
||||
httpPrefix,projectVersion, \
|
||||
boxName!='dm', \
|
||||
showIndividualPostIcons, \
|
||||
manuallyApproveFollowers,False)
|
||||
|
||||
# page down arrow
|
||||
if itemCtr>=itemsPerPage:
|
||||
|
|
Loading…
Reference in New Issue