diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index e5563820..36edc704 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -30,6 +30,48 @@ {% endfor %} + +
+
+ {% for serie in series %} + + {% endfor %} +
+
+ +
+
+ {% for serie in series %} + + {% endfor %} +
+
+ {% if languages %} + +
+
+ {% for language in languages %} + + {% endfor %} +
+
+ +
+
+ {% for language in languages %} + + {% endfor %} +
+
+ {% endif%} diff --git a/cps/ub.py b/cps/ub.py index 9a8f5393..1056ddd6 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -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(): diff --git a/cps/web.py b/cps/web.py index 1969705e..4458700f 100755 --- a/cps/web.py +++ b/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/")