1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-25 09:30:31 +00:00

some fixes for advanced search

This commit is contained in:
Cervinko Cera 2016-05-03 11:00:45 +02:00
parent 7fce28790d
commit 80c3c19c01
3 changed files with 8 additions and 6 deletions

View File

@ -36,3 +36,4 @@ span.glyphicon.glyphicon-tags {padding-right: 5px;color: #999;vertical-align: te
.btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .open .dropdown-toggle.btn-primary{ background-color: #1C5484; }
.btn-primary.disabled, .btn-primary[disabled], fieldset[disabled] .btn-primary, .btn-primary.disabled:hover, .btn-primary[disabled]:hover, fieldset[disabled] .btn-primary:hover, .btn-primary.disabled:focus, .btn-primary[disabled]:focus, fieldset[disabled] .btn-primary:focus, .btn-primary.disabled:active, .btn-primary[disabled]:active, fieldset[disabled] .btn-primary:active, .btn-primary.disabled.active, .btn-primary[disabled].active, fieldset[disabled] .btn-primary.active { background-color: #89B9E2; }
.btn-toolbar>.btn+.btn, .btn-toolbar>.btn-group+.btn, .btn-toolbar>.btn+.btn-group, .btn-toolbar>.btn-group+.btn-group { margin-left:0px; }

View File

@ -29,11 +29,10 @@
<script src="{{ url_for('static', filename='js/typeahead.bundle.js') }}"></script>
<script src="{{ url_for('static', filename='js/edit_books.js') }}"></script>
<script>
$('form').on('change input', function() {
$('form').on('change input typeahead:selected', function() {
form = $('form').serialize();
$.getJSON( "{{ url_for('get_matching_tags') }}", form, function( data ) {
$('.tag_click').each(function() {
console.log(data.tags);
if ($.inArray(parseInt($(this).children('input').first().val(), 10), data.tags) == -1 ) {
$(this).addClass('disabled');
}

View File

@ -451,12 +451,17 @@ def advanced_search():
author_name = request.args.get("author_name")
book_title = request.args.get("book_title")
if tag_inputs or author_name or book_title:
searchterm = []
searchterm.extend((author_name, book_title))
tag_names = db.session.query(db.Tags).filter(db.Tags.id.in_(tag_inputs)).all()
searchterm.extend(tag.name for tag in tag_names)
searchterm = " + ".join(filter(None, searchterm))
q = q.filter(db.Books.authors.any(db.Authors.name.like("%" + author_name + "%")), db.Books.title.like("%"+book_title+"%"))
random = db.session.query(db.Books).order_by(func.random()).limit(config.RANDOM_BOOKS)
for tag in tag_inputs:
q = q.filter(db.Books.tags.any(db.Tags.id == tag))
q = q.all()
return render_template('search.html', searchterm="tags", entries=q)
return render_template('search.html', searchterm=searchterm, entries=q)
tags = db.session.query(db.Tags).order_by(db.Tags.name).all()
return render_template('search_form.html', tags=tags)
@ -958,7 +963,6 @@ def edit_book(book_id):
if len(book.ratings) > 0:
old_rating = book.ratings[0].rating
ratingx2 = int(float(to_save["rating"]) *2)
print ratingx2
if ratingx2 != old_rating:
is_rating = db.session.query(db.Ratings).filter(db.Ratings.rating == ratingx2).first()
if is_rating:
@ -983,7 +987,6 @@ def edit_book(book_id):
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 cc_db_value != None:
#remove old cc_val
@ -1046,7 +1049,6 @@ def edit_book(book_id):
new_tag = db.session.query(db.cc_classes[c.id]).filter(db.cc_classes[c.id].value == add_tag).first()
# if no tag is found add it
if new_tag == None:
print add_tag
new_tag = db.cc_classes[c.id](value=add_tag)
db.session.add(new_tag)
new_tag = db.session.query(db.cc_classes[c.id]).filter(db.cc_classes[c.id].value == add_tag).first()