bookwyrm/bookwyrm/templates/snippets/form_rate_stars.html
Hugh Rundle 230d30abb8 sidebar review stars should default to zero
PR #2283 surfaced an existing formerly-hidden issue with star rating defaults in the sidebar of book pages.
This commit ensures the default rating is zero, not half a star.

Fixes #2291
2022-09-10 07:03:12 +10:00

74 lines
2.4 KiB
HTML

{% spaceless %}
{% load i18n %}
{% load stars %}
<div class="
field is-grouped
stars form-rate-stars
{% if classes %}{{classes}}{% endif%}
">
<input
id="{{ type|slugify }}_{{ book.id }}_no_rating"
class="is-sr-only"
type="radio"
name="rating"
value=""
{% if default_rating == 0 or not default_rating %}checked{% endif %}
>
<label class="is-sr-only" for="{{ type|slugify }}_{{ book.id }}_no_rating">
{% trans "No rating" %}
</label>
{% for i in '12345'|make_list %}
<label
class="is-sr-only"
for="{{ type|slugify }}_book{{ book.id }}_star_{{ forloop.counter0 }}_half"
>
{% blocktranslate trimmed count rating=forloop.counter0 with half_rating=forloop.counter0|half_star %}
{{ half_rating }} star
{% plural %}
{{ half_rating }} stars
{% endblocktranslate %}
</label>
<input
id="{{ type|slugify }}_book{{ book.id }}_star_{{ forloop.counter0 }}_half"
class="is-sr-only half"
type="radio"
name="rating"
value="{{ forloop.counter0 }}.5"
{% if default_rating > 0 and default_rating >= forloop.counter0 %}checked{% endif %}
/>
<input
id="{{ type|slugify }}_book{{ book.id }}_star_{{ forloop.counter }}"
class="is-sr-only"
type="radio"
name="rating"
value="{{ forloop.counter }}"
{% if default_rating >= forloop.counter %}checked{% endif %}
/>
<label
class="
icon
{% if forloop.counter <= default_rating %}
icon-star-full
{% else %}
icon-star-empty
{% endif %}
"
for="{{ type|slugify }}_book{{ book.id }}_star_{{ forloop.counter }}"
data-for-half="{{ type|slugify }}_book{{ book.id }}_star_{{ forloop.counter0 }}_half"
>
<span class="is-sr-only">
{% blocktranslate trimmed count rating=forloop.counter %}
{{ rating }} star
{% plural %}
{{ rating }} stars
{% endblocktranslate %}
</span>
</label>
{% endfor %}
</div>
{% endspaceless %}