folders now relying on ids not names (removes all encoding issues on link folders)

Language filter working in opds feed
removed redundant code
authos now paginating in opds feed
pull/102/head
OzzieIsaacs 8 years ago
parent 176c7dce70
commit e46320b12f

@ -60,28 +60,12 @@
{% endfor %} {% endfor %}
</entry> </entry>
{% endfor %} {% endfor %}
{% for author in authors %} {% for entry in listelements %}
<entry>
<title>{{author.name}}</title>
<id>{{ url_for('feed_author', id=author.id) }}</id>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_author', id=author.id)}}"/>
<link type="application/atom+xml" href="{{url_for('feed_author', id=author.id)}}" rel="subsection"/>
</entry>
{% endfor %}
{% for entry in categorys %}
<entry>
<title>{{entry.name}}</title>
<id>{{ url_for('feed_category', id=entry.id) }}</id>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_category', id=entry.id)}}"/>
<link type="application/atom+xml" href="{{url_for('feed_category', id=entry.id)}}" rel="subsection"/>
</entry>
{% endfor %}
{% for entry in series %}
<entry> <entry>
<title>{{entry.name}}</title> <title>{{entry.name}}</title>
<id>{{ url_for('feed_series', id=entry.id) }}</id> <id>{{ url_for(folder, id=entry.id) }}</id>
<link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for('feed_series', id=entry.id)}}" /> <link type="application/atom+xml;profile=opds-catalog;type=feed;kind=acquisition" href="{{url_for(folder, id=entry.id)}}"/>
<link type="application/atom+xml" href="{{url_for('feed_series', id=entry.id)}}" rel="subsection"/> <link type="application/atom+xml" href="{{url_for(folder, id=entry.id)}}" rel="subsection"/>
</entry> </entry>
{% endfor %} {% endfor %}
</feed> </feed>

@ -18,7 +18,7 @@
</div> </div>
<div class="meta"> <div class="meta">
<p class="title">{{entry.title|shortentitle}}</p> <p class="title">{{entry.title|shortentitle}}</p>
<p class="author"><a href="{{url_for('author', name=entry.authors[0].name) }}">{{entry.authors[0].name}}</a></p> <p class="author"><a href="{{url_for('author', id=entry.authors[0].id) }}">{{entry.authors[0].name}}</a></p>
{% if entry.ratings.__len__() > 0 %} {% if entry.ratings.__len__() > 0 %}
<div class="rating"> <div class="rating">
{% for number in range((entry.ratings[0].rating/2)|int(2)) %} {% for number in range((entry.ratings[0].rating/2)|int(2)) %}
@ -55,7 +55,7 @@
<p class="title">{{entry.title|shortentitle}}</p> <p class="title">{{entry.title|shortentitle}}</p>
<p class="author"> <p class="author">
{% for author in entry.authors %} {% for author in entry.authors %}
<a href="{{url_for('author', name=author.name | urlencode) }}">{{author.name}}</a> <a href="{{url_for('author', id=author.id) }}">{{author.name}}</a>
{% if not loop.last %} {% if not loop.last %}
&amp; &amp;
{% endif %} {% endif %}

@ -5,7 +5,7 @@
{% for entry in entries %} {% for entry in entries %}
<div class="row"> <div class="row">
<div class="col-xs-1" align="left"><span class="badge">{{entry.count}}</span></div> <div class="col-xs-1" align="left"><span class="badge">{{entry.count}}</span></div>
<div class="col-xs-6"><a href="{{url_for(folder, name=entry[0].name | urlencode)}}">{{entry[0].name}}</a></div> <div class="col-xs-6"><a href="{{url_for(folder, id=entry[0].id )}}">{{entry[0].name}}</a></div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>

@ -484,16 +484,10 @@ def feed_search(term):
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_new(): def feed_new():
off = request.args.get("offset") off = request.args.get("offset")
if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Books).filter(filter).order_by(db.Books.timestamp.desc()).offset(off).limit( entries, random, pagination = fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1),
config.config_books_per_page) db.Books, True, db.Books.timestamp.desc())
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(filter).all()))
xml = render_title_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -503,13 +497,10 @@ def feed_new():
@app.route("/opds/discover") @app.route("/opds/discover")
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_discover(): def feed_discover():
# off = request.args.get("start_index")
if current_user.filter_language() != "all": if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else: else:
filter = True filter = True
# if not off:
# off = 0
entries = db.session.query(db.Books).filter(filter).order_by(func.random()).limit(config.config_books_per_page) entries = db.session.query(db.Books).filter(filter).order_by(func.random()).limit(config.config_books_per_page)
pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page)) pagination = Pagination(1, config.config_books_per_page, int(config.config_books_per_page))
xml = render_title_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
@ -522,17 +513,10 @@ def feed_discover():
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_hot(): def feed_hot():
off = request.args.get("offset") off = request.args.get("offset")
if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Books).filter(filter).filter(db.Books.ratings.any(db.Ratings.rating > 9)).offset( entries, random, pagination = fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1),
off).limit(config.config_books_per_page) db.Books, db.Books.ratings.any(db.Ratings.rating > 9), db.Books.timestamp.desc())
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(filter).filter(
db.Books.ratings.any(db.Ratings.rating > 9)).all()))
xml = render_title_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -543,17 +527,17 @@ def feed_hot():
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_authorindex(): def feed_authorindex():
off = request.args.get("offset") off = request.args.get("offset")
# ToDo: Language filter not working if not off:
off = 0
if current_user.filter_language() != "all": if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else: else:
filter = True filter = True
if not off: entries = db.session.query(db.Authors).join(db.books_authors_link).join(db.Books).filter(filter)\
off = 0 .group_by('books_authors_link.author').order_by(db.Authors.sort).limit(config.config_books_per_page).offset(off)
authors = db.session.query(db.Authors).order_by(db.Authors.sort).offset(off).limit(config.config_books_per_page)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Authors).all())) len(db.session.query(db.Authors).all()))
xml = render_title_template('feed.xml', authors=authors, pagination=pagination) xml = render_title_template('feed.xml', listelements=entries, folder='feed_author', pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -563,17 +547,10 @@ def feed_authorindex():
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_author(id): def feed_author(id):
off = request.args.get("offset") off = request.args.get("offset")
if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.id == id)).filter( entries, random, pagination = fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1),
filter).offset(off).limit(config.config_books_per_page) db.Books, db.Books.authors.any(db.Authors.id == id), db.Books.timestamp.desc())
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.id == id)).filter(
filter).all()))
xml = render_title_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -586,10 +563,15 @@ def feed_categoryindex():
off = request.args.get("offset") off = request.args.get("offset")
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Tags).order_by(db.Tags.name).offset(off).limit(config.config_books_per_page) if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
entries = db.session.query(db.Tags).join(db.books_tags_link).join(db.Books).filter(filter).\
group_by('books_tags_link.tag').order_by(db.Tags.name).offset(off).limit(config.config_books_per_page)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Tags).all())) len(db.session.query(db.Tags).all()))
xml = render_title_template('feed.xml', categorys=entries, pagination=pagination) xml = render_title_template('feed.xml', listelements=entries, folder='feed_category', pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -599,17 +581,10 @@ def feed_categoryindex():
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_category(id): def feed_category(id):
off = request.args.get("offset") off = request.args.get("offset")
if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.id == id)).order_by( entries, random, pagination = fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1),
db.Books.timestamp.desc()).filter(filter).offset(off).limit(config.config_books_per_page) db.Books, db.Books.tags.any(db.Tags.id == id), db.Books.timestamp.desc())
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(db.Books.tags.any(db.Tags.id == id)).filter(
filter).all()))
xml = render_title_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -620,16 +595,17 @@ def feed_category(id):
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_seriesindex(): def feed_seriesindex():
off = request.args.get("offset") off = request.args.get("offset")
if not off:
off = 0
if current_user.filter_language() != "all": if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else: else:
filter = True filter = True
if not off: entries = db.session.query(db.Series).join(db.books_series_link).join(db.Books).filter(filter).\
off = 0 group_by('books_series_link.series').order_by(db.Series.sort).offset(off).all()
entries = db.session.query(db.Series).order_by(db.Series.name).offset(off).limit(config.config_books_per_page)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page, pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Series).all())) len(db.session.query(db.Series).all()))
xml = render_title_template('feed.xml', series=entries, pagination=pagination) xml = render_title_template('feed.xml', listelements=entries, folder='feed_series', pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
return response return response
@ -639,17 +615,10 @@ def feed_seriesindex():
@requires_basic_auth_if_no_ano @requires_basic_auth_if_no_ano
def feed_series(id): def feed_series(id):
off = request.args.get("offset") off = request.args.get("offset")
if current_user.filter_language() != "all":
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language())
else:
filter = True
if not off: if not off:
off = 0 off = 0
entries = db.session.query(db.Books).filter(db.Books.series.any(db.Series.id == id)).order_by( entries, random, pagination = fill_indexpage((int(off) / (int(config.config_books_per_page)) + 1),
db.Books.timestamp.desc()).filter(filter).offset(off).limit(config.config_books_per_page) db.Books, db.Books.series.any(db.Series.id == id),db.Books.series_index)
pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
len(db.session.query(db.Books).filter(db.Books.series.any(db.Series.id == id)).filter(
filter).all()))
xml = render_title_template('feed.xml', entries=entries, pagination=pagination) xml = render_title_template('feed.xml', entries=entries, pagination=pagination)
response = make_response(xml) response = make_response(xml)
response.headers["Content-Type"] = "application/xml" response.headers["Content-Type"] = "application/xml"
@ -728,7 +697,6 @@ def get_update_status():
def get_languages_json(): def get_languages_json():
if request.method == "GET": if request.method == "GET":
query = request.args.get('q').lower() query = request.args.get('q').lower()
# entries = db.session.execute("select lang_code from languages where lang_code like '%" + query + "%'")
languages = db.session.query(db.Languages).all() languages = db.session.query(db.Languages).all()
for lang in languages: for lang in languages:
try: try:
@ -736,7 +704,6 @@ def get_languages_json():
lang.name = cur_l.get_language_name(get_locale()) lang.name = cur_l.get_language_name(get_locale())
except: except:
lang.name = _(isoLanguages.get(part3=lang.lang_code).name) lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
entries = [s for s in languages if query in s.name.lower()] entries = [s for s in languages if query in s.name.lower()]
json_dumps = json.dumps([dict(name=r.name) for r in entries]) json_dumps = json.dumps([dict(name=r.name) for r in entries])
return json_dumps return json_dumps
@ -782,8 +749,6 @@ def get_matching_tags():
@app.route('/page/<int:page>') @app.route('/page/<int:page>')
@login_required_if_no_ano @login_required_if_no_ano
def index(page): def index(page):
#if not config.db_configured:
# return redirect(url_for('basic_configuration'))
entries, random, pagination = fill_indexpage(page, db.Books, True, db.Books.timestamp.desc()) entries, random, pagination = fill_indexpage(page, db.Books, True, db.Books.timestamp.desc())
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
title=_(u"Latest Books")) title=_(u"Latest Books"))
@ -836,22 +801,18 @@ def author_list():
return render_title_template('list.html', entries=entries, folder='author', title=_(u"Author list")) return render_title_template('list.html', entries=entries, folder='author', title=_(u"Author list"))
@app.route("/author/<name>") @app.route("/author/<int:id>", defaults={'page': 1})
@app.route("/author/<int:id>/<int:page>'")
@login_required_if_no_ano @login_required_if_no_ano
def author(name): def author(id,page):
name=requests.utils.unquote(name) entries, random, pagination = fill_indexpage(page, db.Books, db.Books.authors.any(db.Authors.id == id),
if current_user.filter_language() != "all": db.Books.timestamp.desc())
filter = db.Books.languages.any(db.Languages.lang_code == current_user.filter_language()) name = db.session.query(db.Authors).filter(db.Authors.id == id).first().name
else: if entries:
filter = True return render_title_template('index.html', random=random, entries=entries, title=_(u"Author: %(name)s", name=name))
if current_user.show_detail_random():
random = db.session.query(db.Books).filter(filter).order_by(func.random()).limit(config.config_random_books)
else: else:
random = false flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect(url_for("index"))
entries = db.session.query(db.Books).filter(db.Books.authors.any(db.Authors.name.like("%" + name + "%"))).filter(
filter).all()
return render_title_template('index.html', random=random, entries=entries, title=_(u"Author: %(nam)s", nam=name))
@app.route("/series") @app.route("/series")
@ -867,13 +828,13 @@ def series_list():
return render_title_template('list.html', entries=entries, folder='series', title=_(u"Series list")) return render_title_template('list.html', entries=entries, folder='series', title=_(u"Series list"))
@app.route("/series/<name>/", defaults={'page': 1}) @app.route("/series/<int:id>/", defaults={'page': 1})
@app.route("/series/<name>/<int:page>'") @app.route("/series/<int:id>/<int:page>'")
@login_required_if_no_ano @login_required_if_no_ano
def series(name, page): def series(id, page):
name = requests.utils.unquote(name) entries, random, pagination = fill_indexpage(page, db.Books, db.Books.series.any(db.Series.id == id),
entries, random, pagination = fill_indexpage(page, db.Books, db.Books.series.any(db.Series.name == name),
db.Books.series_index) db.Books.series_index)
name=db.session.query(db.Series).filter(db.Series.id == id).first().name
if entries: if entries:
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, return render_title_template('index.html', random=random, pagination=pagination, entries=entries,
title=_(u"Series: %(serie)s", serie=name)) title=_(u"Series: %(serie)s", serie=name))
@ -940,13 +901,14 @@ def category_list():
return render_title_template('list.html', entries=entries, folder='category', title=_(u"Category list")) return render_title_template('list.html', entries=entries, folder='category', title=_(u"Category list"))
@app.route("/category/<name>", defaults={'page': 1}) @app.route("/category/<int:id>", defaults={'page': 1})
@app.route('/category/<name>/<int:page>') @app.route('/category/<int:id>/<int:page>')
@login_required_if_no_ano @login_required_if_no_ano
def category(name, page): def category(id, page):
name = requests.utils.unquote(name) entries, random, pagination = fill_indexpage(page, db.Books, db.Books.tags.any(db.Tags.id == id),
entries, random, pagination = fill_indexpage(page, db.Books, db.Books.tags.any(db.Tags.name == name),
db.Books.timestamp.desc()) db.Books.timestamp.desc())
name=db.session.query(db.Tags).filter(db.Tags.id == id).first().name
return render_title_template('index.html', random=random, entries=entries, pagination=pagination, return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
title=_(u"Category: %(name)s", name=name)) title=_(u"Category: %(name)s", name=name))

Loading…
Cancel
Save