From 8840e09eacd5379d244e9127a7309c1b32fc8512 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 10 Sep 2021 14:41:55 -0700 Subject: [PATCH] Fixes labels --- bookwyrm/templates/snippets/form_rate_stars.html | 3 ++- bookwyrm/templatetags/stars.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 bookwyrm/templatetags/stars.py diff --git a/bookwyrm/templates/snippets/form_rate_stars.html b/bookwyrm/templates/snippets/form_rate_stars.html index dfd5a758c..302f181ed 100644 --- a/bookwyrm/templates/snippets/form_rate_stars.html +++ b/bookwyrm/templates/snippets/form_rate_stars.html @@ -1,5 +1,6 @@ {% spaceless %} {% load i18n %} +{% load stars %}
- {% blocktranslate trimmed count rating=forloop.counter0 with half_rating=forloop.counter0|add:""|add:"0.5" %} + {% blocktranslate trimmed count rating=forloop.counter0 with half_rating=forloop.counter0|half_star %} {{ half_rating }} star {% plural %} {{ half_rating }} stars diff --git a/bookwyrm/templatetags/stars.py b/bookwyrm/templatetags/stars.py new file mode 100644 index 000000000..d08dd8ef0 --- /dev/null +++ b/bookwyrm/templatetags/stars.py @@ -0,0 +1,11 @@ +""" template filters """ +from django import template + + +register = template.Library() + + +@register.filter(name="half_star") +def get_half_star(value): + """one of those things that's weirdly hard with templates""" + return f"{value}.5"