mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
Tweak Question
display
This commit is contained in:
parent
6307477871
commit
d7aa685e22
2 changed files with 27 additions and 9 deletions
25
app.py
25
app.py
|
@ -442,9 +442,28 @@ def is_img(filename):
|
||||||
|
|
||||||
|
|
||||||
@app.template_filter()
|
@app.template_filter()
|
||||||
def get_answer_count(choice, meta):
|
def get_answer_count(choice, obj, meta):
|
||||||
print(choice, meta)
|
count_from_meta = meta.get("question_answers", {}).get(_answer_key(choice), 0)
|
||||||
return meta.get("question_answers", {}).get(_answer_key(choice), 0)
|
print(count_from_meta)
|
||||||
|
print(choice, obj, meta)
|
||||||
|
if count_from_meta:
|
||||||
|
return count_from_meta
|
||||||
|
for option in obj.get("oneOf", obj.get("anyOf", [])):
|
||||||
|
if option.get("name") == choice:
|
||||||
|
return option.get("replies", {}).get("totalItems", 0)
|
||||||
|
|
||||||
|
|
||||||
|
@app.template_filter()
|
||||||
|
def get_total_answers_count(obj, meta):
|
||||||
|
cached = meta.get("question_replies", 0)
|
||||||
|
if cached:
|
||||||
|
return cached
|
||||||
|
cnt = 0
|
||||||
|
print("OKI", obj)
|
||||||
|
for choice in obj.get("anyOf", obj.get("oneOf", [])):
|
||||||
|
print(choice)
|
||||||
|
cnt += choice.get("replies", {}).get("totalItems", 0)
|
||||||
|
return cnt
|
||||||
|
|
||||||
|
|
||||||
def add_response_headers(headers={}):
|
def add_response_headers(headers={}):
|
||||||
|
|
|
@ -76,14 +76,13 @@
|
||||||
{% elif obj | has_type('Question') %}
|
{% elif obj | has_type('Question') %}
|
||||||
{{ obj.content | clean | safe }}
|
{{ obj.content | clean | safe }}
|
||||||
|
|
||||||
{% if obj.id | is_from_outbox or (meta.question_replies and (obj.closed or meta.voted_for)) %}
|
{% if obj.id | is_from_outbox or obj.closed or meta.voted_for %}
|
||||||
<ul style="list-style:none;padding:0;">
|
<ul style="list-style:none;padding:0;">
|
||||||
{% set total_votes = meta.question_replies %}
|
{% set total_votes = obj | get_total_answers_count(meta) %}
|
||||||
|
|
||||||
{% for oneOf in obj.oneOf %}
|
{% for oneOf in obj.oneOf %}
|
||||||
{% set pct = 0 %}
|
{% set pct = 0 %}
|
||||||
{% if total_votes > 0 %}
|
{% if total_votes > 0 %}
|
||||||
{% set cnt = oneOf.name | get_answer_count(meta) %}
|
{% set cnt = oneOf.name | get_answer_count(obj, meta) %}
|
||||||
{% set pct = cnt * 100.0 / total_votes %}
|
{% set pct = cnt * 100.0 / total_votes %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="answer">
|
<li class="answer">
|
||||||
|
@ -97,9 +96,9 @@
|
||||||
</ul>
|
</ul>
|
||||||
<p><small>
|
<p><small>
|
||||||
{% if real_end_time | gtnow %}
|
{% if real_end_time | gtnow %}
|
||||||
Ended {{ obj.endTime | format_timeago }} with <strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %}.
|
Ended {{ real_end_time | format_timeago }} with <strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %}.
|
||||||
{% else %}
|
{% else %}
|
||||||
Ends {{ obj.endTime | format_timeago }} (<strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %} as of now).
|
Ends {{ real_end_time | format_timeago }} (<strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %} as of now).
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</small></p>
|
</small></p>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
Loading…
Reference in a new issue