mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
post_to_page: add Poll post type
This commit is contained in:
parent
e6b3a5bd7c
commit
7cfe89a92e
1 changed files with 17 additions and 0 deletions
|
@ -235,6 +235,23 @@ def post_to_page(post: Post):
|
|||
activity_data["image"] = {"url": post.image.view_url(), "type": "Image"}
|
||||
if post.image.alt_text:
|
||||
activity_data["image"]['altText'] = post.image.alt_text
|
||||
if post.type == POST_TYPE_POLL:
|
||||
poll = Poll.query.filter_by(post_id=post.id).first()
|
||||
activity_data['type'] = 'Question'
|
||||
mode = 'oneOf' if poll.mode == 'single' else 'anyOf'
|
||||
choices = []
|
||||
for choice in PollChoice.query.filter_by(post_id=post.id).order_by(PollChoice.sort_order).all():
|
||||
choices.append({
|
||||
"type": "Note",
|
||||
"name": choice.choice_text,
|
||||
"replies": {
|
||||
"type": "Collection",
|
||||
"totalItems": choice.num_votes
|
||||
}
|
||||
})
|
||||
activity_data[mode] = choices
|
||||
activity_data['endTime'] = ap_datetime(poll.end_poll)
|
||||
activity_data['votersCount'] = poll.total_votes()
|
||||
return activity_data
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue