Skip to content

Commit

Permalink
Add basic display of polls
Browse files Browse the repository at this point in the history
Need to change the outer <table> to a <div style="display:table"> to
avoid HTML nesting issues (we can't use normal tables due to NNW quirks, see
18cfcb0 and 0370b5e).
  • Loading branch information
mihaip committed Dec 11, 2022
1 parent e21a78c commit 4fad51a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions app/datasources/mastodondisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ def get_status_title_text(status):
display_name(status.reblog.account),
get_status_title_text(status.reblog),
)
if status.reblog.poll:
title_text += u' 📊'
else:
title_text = get_status_title_text(status)
if status.poll:
title_text += u' 📊'

return u'%s: %s' % (display_name(status.account), title_text)

Expand All @@ -97,6 +101,14 @@ def content_as_html(self):
if html.startswith('<p>') and html.endswith('</p>'):
html = html[3:-4].replace('</p><p>', '<br><br>')

if status.poll:
html += '<table border="1" cellspacing="0" cellpadding="2" style="border-collapse:collapse">'
html += '<caption style="background:#00000011">Poll</caption>'
for option in status.poll.options:
percent = 100.0 * option.votes_count / status.poll.votes_count
html += '<tr><td>%s</td><td>%.2f%%</td></tr>' % (option.title, percent)
html += '</table>'

for attachment in status.media_attachments:
html += '<p>'
if attachment.type == 'image':
Expand Down
4 changes: 2 additions & 2 deletions app/templates/mastofeeder/feed.atom
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<updated>{{ display_status.updated_at_iso }}Z</updated>
<content type="html">
{% filter force_escape %}
<table style="border-spacing:0;border-collapse:collapse;font-family:sans-serif;font-size:inherit;font-weight:inherit;font-style:inherit;font-variant:inherit;color:{{ BUBBLE_TEXT_COLOR }};width:100%" cellpadding="0">
<div style="display:table;border-spacing:0;border-collapse:collapse;font-family:sans-serif;font-size:inherit;font-weight:inherit;font-style:inherit;font-variant:inherit;color:{{ BUBBLE_TEXT_COLOR }};width:100%" cellpadding="0">
{% include 'status.snippet' %}
</table>
</div>
{% endfilter %}
</content>
{% if include_status_json %}
Expand Down
4 changes: 2 additions & 2 deletions app/templates/mastofeeder/feed.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

{% block body %}
{% for display_status in display_statuses %}
<table style="border-spacing:0;border-collapse:collapse;font-family:sans-serif;font-size:inherit;font-weight:inherit;font-style:inherit;font-variant:inherit;color:{{ BUBBLE_TEXT_COLOR }};width:100%;margin-bottom:1em;" cellpadding="0">
<div style="display:table;border-spacing:0;border-collapse:collapse;font-family:sans-serif;font-size:inherit;font-weight:inherit;font-style:inherit;font-variant:inherit;color:{{ BUBBLE_TEXT_COLOR }};width:100%;margin-bottom:1em;" cellpadding="0">
{% include 'status.snippet' %}
</table>
</div>
{% endfor %}
{% endblock %}

Expand Down

0 comments on commit 4fad51a

Please sign in to comment.