mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 13:14: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()
|
||||
def get_answer_count(choice, meta):
|
||||
print(choice, meta)
|
||||
return meta.get("question_answers", {}).get(_answer_key(choice), 0)
|
||||
def get_answer_count(choice, obj, meta):
|
||||
count_from_meta = 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={}):
|
||||
|
|
|
@ -76,14 +76,13 @@
|
|||
{% elif obj | has_type('Question') %}
|
||||
{{ 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;">
|
||||
{% set total_votes = meta.question_replies %}
|
||||
|
||||
{% set total_votes = obj | get_total_answers_count(meta) %}
|
||||
{% for oneOf in obj.oneOf %}
|
||||
{% set pct = 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 %}
|
||||
{% endif %}
|
||||
<li class="answer">
|
||||
|
@ -97,9 +96,9 @@
|
|||
</ul>
|
||||
<p><small>
|
||||
{% 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 %}
|
||||
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 %}
|
||||
</small></p>
|
||||
{% else %}
|
||||
|
|
Loading…
Reference in a new issue