mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-24 18:47:23 +00:00
Add search for series and languages (#56)
Add database migration for shelf ordering (#73)
This commit is contained in:
parent
fac83a10eb
commit
c33a329f08
@ -30,6 +30,48 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<label for="Series">{{_('Series')}}</label>
|
||||
<div class="form-group">
|
||||
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
||||
{% for serie in series %}
|
||||
<label id="serie_{{serie.id}}" class="btn btn-primary serie_click">
|
||||
<input type="checkbox" autocomplete="off" name="include_serie" value="{{serie.id}}">{{serie.name}}</input>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<label for="Tags">{{_('Exclude Series')}}</label>
|
||||
<div class="form-group">
|
||||
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
||||
{% for serie in series %}
|
||||
<label id="serie_{{serie.id}}" class="btn btn-danger serie_click">
|
||||
<input type="checkbox" autocomplete="off" name="exclude_serie" value="{{serie.id}}">{{serie.name}}</input>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% if languages %}
|
||||
<label for="Languages">{{_('Languages')}}</label>
|
||||
<div class="form-group">
|
||||
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
||||
{% for language in languages %}
|
||||
<label id="language_{{language.id}}" class="btn btn-primary serie_click">
|
||||
<input type="checkbox" autocomplete="off" name="include_language" value="{{language.id}}">{{language.name}}</input>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<label for="Languages">{{_('Exclude Languages')}}</label>
|
||||
<div class="form-group">
|
||||
<div class="btn-toolbar btn-toolbar-lg" data-toggle="buttons">
|
||||
{% for language in languages %}
|
||||
<label id="language_{{language.id}}" class="btn btn-danger language_click">
|
||||
<input type="checkbox" autocomplete="off" name="exclude_language" value="{{language.id}}">{{language.name}}</input>
|
||||
</label>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif%}
|
||||
<button type="submit" class="btn btn-default">{{_('Submit')}}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -174,6 +174,13 @@ def migrate_Database():
|
||||
conn.execute("ALTER TABLE user ADD column category_books INTEGER DEFAULT 1")
|
||||
conn.execute("ALTER TABLE user ADD column hot_books INTEGER DEFAULT 1")
|
||||
session.commit()
|
||||
try:
|
||||
session.query(exists().where(BookShelf.order)).scalar()
|
||||
session.commit()
|
||||
except exc.OperationalError: # Database is not compatible, some rows are missing
|
||||
conn = engine.connect()
|
||||
conn.execute("ALTER TABLE book_shelf_link ADD column order INTEGER DEFAULT 1")
|
||||
session.commit()
|
||||
|
||||
|
||||
def create_default_config():
|
||||
|
42
cps/web.py
42
cps/web.py
@ -969,29 +969,65 @@ def advanced_search():
|
||||
q = db.session.query(db.Books)
|
||||
include_tag_inputs = request.args.getlist('include_tag')
|
||||
exclude_tag_inputs = request.args.getlist('exclude_tag')
|
||||
include_series_inputs = request.args.getlist('include_serie')
|
||||
exclude_series_inputs = request.args.getlist('exclude_serie')
|
||||
include_languages_inputs = request.args.getlist('include_language')
|
||||
exclude_languages_inputs = request.args.getlist('exclude_language')
|
||||
|
||||
author_name = request.args.get("author_name")
|
||||
book_title = request.args.get("book_title")
|
||||
if author_name: author_name = author_name.strip()
|
||||
if book_title: book_title = book_title.strip()
|
||||
if include_tag_inputs or exclude_tag_inputs or author_name or book_title:
|
||||
if include_tag_inputs or exclude_tag_inputs or include_series_inputs or exclude_series_inputs or \
|
||||
include_languages_inputs or exclude_languages_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_(include_tag_inputs)).all()
|
||||
searchterm.extend(tag.name for tag in tag_names)
|
||||
# searchterm = " + ".join(filter(None, searchterm))
|
||||
serie_names = db.session.query(db.Series).filter(db.Series.id.in_(include_series_inputs)).all()
|
||||
searchterm.extend(serie.name for serie in serie_names)
|
||||
language_names = db.session.query(db.Languages).filter(db.Languages.id.in_(include_languages_inputs)).all()
|
||||
for lang in language_names:
|
||||
try:
|
||||
cur_l = LC.parse(lang.lang_code)
|
||||
lang.name = cur_l.get_language_name(get_locale())
|
||||
except:
|
||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
||||
searchterm.extend(language.name for language in language_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 include_tag_inputs:
|
||||
q = q.filter(db.Books.tags.any(db.Tags.id == tag))
|
||||
for tag in exclude_tag_inputs:
|
||||
q = q.filter(not_(db.Books.tags.any(db.Tags.id == tag)))
|
||||
for serie in include_series_inputs:
|
||||
q = q.filter(db.Books.series.any(db.Series.id == serie))
|
||||
for serie in exclude_series_inputs:
|
||||
q = q.filter(not_(db.Books.series.any(db.Series.id == serie)))
|
||||
if current_user.filter_language() != "all":
|
||||
q = q.filter(db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()))
|
||||
else:
|
||||
for language in include_languages_inputs:
|
||||
q = q.filter(db.Books.languages.any(db.Languages.id == language))
|
||||
for language in exclude_languages_inputs:
|
||||
q = q.filter(not_(db.Books.series.any(db.Languages.id == language)))
|
||||
q = q.all()
|
||||
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)
|
||||
series = db.session.query(db.Series).order_by(db.Series.name).all()
|
||||
if current_user.filter_language() == u"all":
|
||||
languages = db.session.query(db.Languages).all()
|
||||
for lang in languages:
|
||||
try:
|
||||
cur_l = LC.parse(lang.lang_code)
|
||||
lang.name = cur_l.get_language_name(get_locale())
|
||||
except:
|
||||
lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
|
||||
else:
|
||||
languages=None
|
||||
return render_template('search_form.html', tags=tags, languages=languages, series=series)
|
||||
|
||||
|
||||
@app.route("/cover/<path:cover_path>")
|
||||
|
Loading…
Reference in New Issue
Block a user