Fixes rate action

This commit is contained in:
Mouse Reeve 2021-01-18 09:57:44 -08:00
parent debc9696e1
commit c7b03fec5a
5 changed files with 39 additions and 11 deletions

View file

@ -23,7 +23,7 @@
} }
.hidden { .hidden {
display: none; display: none !important;
} }
/* --- STARS --- */ /* --- STARS --- */

View file

@ -27,8 +27,20 @@ window.onload = function() {
// update localstorage // update localstorage
Array.from(document.getElementsByClassName('set-display')) Array.from(document.getElementsByClassName('set-display'))
.forEach(t => t.onclick = updateDisplay); .forEach(t => t.onclick = updateDisplay);
// hidden submit button in a form
document.querySelectorAll('.hidden-form input')
.forEach(t => t.onchange = revealForm);
}; };
function revealForm(e) {
var hidden = e.currentTarget.closest('.hidden-form').getElementsByClassName('hidden')[0];
if (hidden) {
removeClass(hidden, 'hidden');
}
}
function updateDisplay(e) { function updateDisplay(e) {
// used in set reading goal // used in set reading goal
var key = e.target.getAttribute('data-id'); var key = e.target.getAttribute('data-id');

View file

@ -1,5 +1,5 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
<div class="select"> <div class="select {{ class }}">
{% with 0|uuid as uuid %} {% with 0|uuid as uuid %}
{% if not no_label %} {% if not no_label %}
<label class="is-sr-only" for="privacy-{{ uuid }}">Post privacy</label> <label class="is-sr-only" for="privacy-{{ uuid }}">Post privacy</label>

View file

@ -1,18 +1,33 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<span class="is-sr-only">Leave a rating</span> <span class="is-sr-only">Leave a rating</span>
<div class="field is-grouped stars rate-stars"> <div class="block">
{% for i in '12345'|make_list %} <form class="hidden-form" name="rate" action="/post/rating" method="POST">
<form name="rate" action="/rate/" method="POST">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ request.user.id }}"> <input type="hidden" name="user" value="{{ request.user.id }}">
<input type="hidden" name="book" value="{{ book.id }}"> <input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="privacy" value="public"> <input type="hidden" name="privacy" value="public">
<input type="hidden" name="rating" value="{{ forloop.counter }}"> <input type="hidden" name="rating" value="{{ forloop.counter }}">
<button type="submit" class="icon icon-star-{% if book|rating:user < forloop.counter %}empty{% else %}full{% endif %}">
<div class="field is-grouped stars form-rate-stars mb-1">
<label class="is-sr-only" for="no-rating-{{ book.id }}">No rating</label>
<input class="is-sr-only" type="radio" name="rating" value="" id="no-rating-{{ book.id }}" checked>
{% for i in '12345'|make_list %}
<input class="is-sr-only" id="book{{book.id}}-star-{{ forloop.counter }}" type="radio" name="rating" value="{{ forloop.counter }}" {% if book|rating:user == forloop.counter %}checked{% endif %}>
<label class="icon icon-star-empty" for="book{{book.id}}-star-{{ forloop.counter }}">
<span class="is-sr-only">{{ forloop.counter }} star{{ forloop.counter | pluralize }}</span> <span class="is-sr-only">{{ forloop.counter }} star{{ forloop.counter | pluralize }}</span>
</button> </label>
</form>
{% endfor %} {% endfor %}
</div>
<div class="field has-addons hidden">
<div class="control">
{% include 'snippets/privacy_select.html' with class="is-small" %}
</div>
<div class="control">
<button class="button is-small is-primary" type="submit">Rate</button>
</div>
</div>
</form>
</div> </div>
{% endif %} {% endif %}

View file

@ -21,7 +21,7 @@ from .helpers import is_api_request, is_bookworm_request, object_visible_to_user
# pylint: disable= no-self-use # pylint: disable= no-self-use
class Status(View): class Status(View):
''' the view for *posting* ''' ''' get posting '''
def get(self, request, username, status_id): def get(self, request, username, status_id):
''' display a particular status (and replies, etc) ''' ''' display a particular status (and replies, etc) '''
try: try:
@ -52,10 +52,11 @@ class Status(View):
@method_decorator(login_required, name='dispatch') @method_decorator(login_required, name='dispatch')
class CreateStatus(View): class CreateStatus(View):
''' get posting ''' ''' the view for *posting* '''
def post(self, request, status_type): def post(self, request, status_type):
''' create status of whatever type ''' ''' create status of whatever type '''
status_type = status_type[0].upper() + status_type[1:] status_type = status_type[0].upper() + status_type[1:]
try: try:
form = getattr(forms, '%sForm' % status_type)(request.POST) form = getattr(forms, '%sForm' % status_type)(request.POST)
except AttributeError: except AttributeError: