fix for custom column 'rating'

This commit is contained in:
Cervinko Cera 2016-04-21 12:46:26 +02:00
parent a21a9d6510
commit 931981a37a
2 changed files with 6 additions and 4 deletions

View File

@ -70,9 +70,7 @@
{% if c.datatype == 'rating' %} {% if c.datatype == 'rating' %}
<input type="number" min="1" max="5" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" <input type="number" min="1" max="5" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"
{% if book['custom_column_' ~ c.id]|length > 0 %} {% if book['custom_column_' ~ c.id]|length > 0 %}
{% for column in book['custom_column_' ~ c.id] %} value="{{ book['custom_column_' ~ c.id][0].value / 2 }}"
value="{{ column.value }}{% if not loop.last %}, {% endif %}
{% endfor %}"
{% endif %}> {% endif %}>
{% endif %} {% endif %}
</div> </div>

View File

@ -822,7 +822,8 @@ def edit_book(book_id):
old_rating = False old_rating = False
if len(book.ratings) > 0: if len(book.ratings) > 0:
old_rating = book.ratings[0].rating old_rating = book.ratings[0].rating
ratingx2 = int(to_save["rating"]) *2 ratingx2 = int(float(to_save["rating"]) *2)
print ratingx2
if ratingx2 != old_rating: if ratingx2 != old_rating:
is_rating = db.session.query(db.Ratings).filter(db.Ratings.rating == ratingx2).first() is_rating = db.session.query(db.Ratings).filter(db.Ratings.rating == ratingx2).first()
if is_rating: if is_rating:
@ -844,6 +845,9 @@ def edit_book(book_id):
else: else:
cc_db_value = None cc_db_value = None
if to_save[cc_string].strip(): if to_save[cc_string].strip():
if c.datatype == 'rating':
to_save[cc_string] = str(int(float(to_save[cc_string]) *2))
print to_save[cc_string]
if to_save[cc_string].strip() != cc_db_value: if to_save[cc_string].strip() != cc_db_value:
if cc_db_value != None: if cc_db_value != None:
#remove old cc_val #remove old cc_val