Simplify rating form:

- Create a snippet to regroup similar code.
- Reduce and document tricky logic of CSS.
- Add i18n strings.
This commit is contained in:
Fabien Basmaison
2021-04-04 15:08:42 +02:00
parent 7b3c85f351
commit 485b0fa0f3
7 changed files with 189 additions and 132 deletions

View File

@ -8,18 +8,8 @@
<input type="hidden" name="user" value="{{ request.user.id }}">
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="privacy" value="public">
<input type="hidden" name="rating" value="{{ forloop.counter }}">
<div class="field is-grouped stars form-rate-stars mb-1 has-text-warning-dark">
<label class="is-sr-only" for="rating-no-rating-{{ book.id }}">{% trans "No rating" %}</label>
<input class="is-sr-only" type="radio" name="rating" value="" id="rating-no-rating-{{ book.id }}" checked>
{% for i in '12345'|make_list %}
<input class="is-sr-only" id="rating-book{{book.id}}-star-{{ forloop.counter }}" type="radio" name="rating" value="{{ forloop.counter }}" {% if book|user_rating:user == forloop.counter %}checked{% endif %}>
<label class="icon icon-star-empty" for="rating-book{{book.id}}-star-{{ forloop.counter }}">
<span class="is-sr-only">{{ forloop.counter }} star{{ forloop.counter | pluralize }}</span>
</label>
{% endfor %}
</div>
{% include 'snippets/form_rate_stars.html' with book=book classes='mb-1 has-text-warning-dark' %}
<div class="field has-addons hidden">
<div class="control">