From b496c95f107ff8978df9347e583ea50a9a34a96e Mon Sep 17 00:00:00 2001 From: SouthFox Date: Tue, 15 Nov 2022 18:08:03 +0800 Subject: [PATCH] feat/support show poll --- BDSM/views.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/BDSM/views.py b/BDSM/views.py index ff2b0e3..d0a9570 100644 --- a/BDSM/views.py +++ b/BDSM/views.py @@ -1,11 +1,12 @@ #!/usr/bin/env python3 import os import pytz +import json from flask import render_template, request, url_for, redirect, flash, abort from flask_sqlalchemy import Pagination from BDSM import app, db -from BDSM.models import Media, Settings, Toot, Emoji, Other +from BDSM.models import Media, Poll, Settings, Toot, Emoji, Other from BDSM.toot import app_register, archive_toot, get_context from mastodon import Mastodon from types import SimpleNamespace @@ -235,5 +236,16 @@ def process_toot(toots_): ''' toot.content = toot.content.replace(emoji_shortcode, emoji_html) + if toot.poll_id != None: + poll = Poll.query.get(toot.poll_id) + poll_options = json.loads(poll.options.replace("\'", "\"")) + poll_count = str(poll.votes_count) + poll_content = '总票数: ' + poll_count + '
' + + for i in poll_options: + poll_content += i['title'] + " / " + str(i['votes_count']) + '
' + + toot.content += poll_content + toots.append(toot) return toots