fixed url_for return without port when port is not the standard port.

This commit is contained in:
idalin 2017-01-16 16:18:53 +08:00
parent 0458ea5acb
commit eb22fbf9fa

View File

@ -828,7 +828,7 @@ def series(name, page):
title=_(u"Series: %(serie)s", serie=name)) title=_(u"Series: %(serie)s", serie=name))
else: else:
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect(url_for("index")) return redirect(url_for("index", _external=True))
@app.route("/language") @app.route("/language")
@ -924,7 +924,7 @@ def show_book(id):
return render_template('detail.html', entry=entries, cc=cc, title=entries.title, books_shelfs=book_in_shelfs) return render_template('detail.html', entry=entries, cc=cc, title=entries.title, books_shelfs=book_in_shelfs)
else: else:
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect(url_for("index")) return redirect(url_for("index", _external=True))
@app.route("/admin") @app.route("/admin")
@ -1162,7 +1162,7 @@ def register():
if not config.PUBLIC_REG: if not config.PUBLIC_REG:
abort(404) abort(404)
if current_user is not None and current_user.is_authenticated: if current_user is not None and current_user.is_authenticated:
return redirect(url_for('index')) return redirect(url_for('index', _external=True))
if request.method == "POST": if request.method == "POST":
to_save = request.form.to_dict() to_save = request.form.to_dict()
@ -1186,7 +1186,7 @@ def register():
flash(_(u"An unknown error occured. Please try again later."), category="error") flash(_(u"An unknown error occured. Please try again later."), category="error")
return render_template('register.html', title="register") return render_template('register.html', title="register")
flash("Your account has been created. Please login.", category="success") flash("Your account has been created. Please login.", category="success")
return redirect(url_for('login')) return redirect(url_for('login', _external=True))
else: else:
flash(_(u"This username or email address is already in use."), category="error") flash(_(u"This username or email address is already in use."), category="error")
return render_template('register.html', title="register") return render_template('register.html', title="register")
@ -1199,7 +1199,7 @@ def login():
error = None error = None
if current_user is not None and current_user.is_authenticated: if current_user is not None and current_user.is_authenticated:
return redirect(url_for('index')) return redirect(url_for('index', _external=True))
if request.method == "POST": if request.method == "POST":
form = request.form.to_dict() form = request.form.to_dict()
@ -1209,7 +1209,7 @@ def login():
login_user(user, remember=True) login_user(user, remember=True)
flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success") flash(_(u"you are now logged in as: '%(nickname)s'", nickname=user.nickname), category="success")
# test= # test=
return redirect(url_for("index")) return redirect(url_for("index", _external=True))
else: else:
flash(_(u"Wrong Username or Password"), category="error") flash(_(u"Wrong Username or Password"), category="error")
@ -1221,7 +1221,7 @@ def login():
def logout(): def logout():
if current_user is not None and current_user.is_authenticated: if current_user is not None and current_user.is_authenticated:
logout_user() logout_user()
return redirect(url_for('login')) return redirect(url_for('login', _external=True))
@app.route('/send/<int:book_id>') @app.route('/send/<int:book_id>')
@ -1250,7 +1250,7 @@ def add_to_shelf(shelf_id, book_id):
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
if not shelf.is_public and not shelf.user_id == int(current_user.id): if not shelf.is_public and not shelf.user_id == int(current_user.id):
flash("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name) flash("Sorry you are not allowed to add a book to the the shelf: %s" % shelf.name)
return redirect(url_for('index')) return redirect(url_for('index', _external=True))
maxO = ub.session.query(func.max(ub.BookShelf.order)).filter(ub.BookShelf.shelf == shelf_id).first() maxO = ub.session.query(func.max(ub.BookShelf.order)).filter(ub.BookShelf.shelf == shelf_id).first()
if maxO[0] is None: if maxO[0] is None:
maxOrder = 0 maxOrder = 0
@ -1272,7 +1272,7 @@ def remove_from_shelf(shelf_id, book_id):
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first() shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
if not shelf.is_public and not shelf.user_id == int(current_user.id): if not shelf.is_public and not shelf.user_id == int(current_user.id):
flash("Sorry you are not allowed to remove a book from this shelf: %s" % shelf.name) flash("Sorry you are not allowed to remove a book from this shelf: %s" % shelf.name)
return redirect(url_for('index')) return redirect(url_for('index', _external=True))
book_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id, book_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id,
ub.BookShelf.book_id == book_id).first() ub.BookShelf.book_id == book_id).first()
@ -1356,7 +1356,7 @@ def delete_shelf(shelf_id):
ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).delete() ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).delete()
ub.session.commit() ub.session.commit()
flash(_("successfully deleted shelf %(name)s", name=cur_shelf.name, category="success")) flash(_("successfully deleted shelf %(name)s", name=cur_shelf.name, category="success"))
return redirect(url_for('index')) return redirect(url_for('index', _external=True))
@app.route("/shelf/<int:shelf_id>") @app.route("/shelf/<int:shelf_id>")
@ -1540,7 +1540,7 @@ def new_user():
ub.session.add(content) ub.session.add(content)
ub.session.commit() ub.session.commit()
flash(_("User '%(user)s' created", user=content.nickname), category="success") flash(_("User '%(user)s' created", user=content.nickname), category="success")
return redirect(url_for('admin')) return redirect(url_for('admin', _external=True))
except IntegrityError: except IntegrityError:
ub.session.rollback() ub.session.rollback()
flash(_(u"Found an existing account for this email address or nickname."), category="error") flash(_(u"Found an existing account for this email address or nickname."), category="error")
@ -1605,7 +1605,7 @@ def edit_user(user_id):
if "delete" in to_save: if "delete" in to_save:
ub.session.delete(content) ub.session.delete(content)
flash(_(u"User '%(nick)s' deleted", nick=content.nickname), category="success") flash(_(u"User '%(nick)s' deleted", nick=content.nickname), category="success")
return redirect(url_for('admin')) return redirect(url_for('admin', _external=True))
else: else:
if "password" in to_save and to_save["password"]: if "password" in to_save and to_save["password"]:
content.password = generate_password_hash(to_save["password"]) content.password = generate_password_hash(to_save["password"])
@ -1866,14 +1866,14 @@ def edit_book(book_id):
for b in edited_books_id: for b in edited_books_id:
helper.update_dir_stucture(b) helper.update_dir_stucture(b)
if "detail_view" in to_save: if "detail_view" in to_save:
return redirect(url_for('show_book', id=book.id)) return redirect(url_for('show_book', id=book.id, _external=True))
else: else:
return render_template('edit_book.html', book=book, authors=author_names, cc=cc) return render_template('edit_book.html', book=book, authors=author_names, cc=cc)
else: else:
return render_template('edit_book.html', book=book, authors=author_names, cc=cc) return render_template('edit_book.html', book=book, authors=author_names, cc=cc)
else: else:
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
return redirect(url_for("index")) return redirect(url_for("index", _external=True))
@app.route("/upload", methods=["GET", "POST"]) @app.route("/upload", methods=["GET", "POST"])
@ -1903,12 +1903,12 @@ def upload():
os.makedirs(filepath) os.makedirs(filepath)
except OSError: except OSError:
flash(_(u"Failed to create path %s (Permission denied)." % filepath), category="error") flash(_(u"Failed to create path %s (Permission denied)." % filepath), category="error")
return redirect(url_for('index')) return redirect(url_for('index', _external=True))
try: try:
copyfile(meta.file_path, saved_filename) copyfile(meta.file_path, saved_filename)
except OSError, e: except OSError, e:
flash(_(u"Failed to store file %s (Permission denied)." % saved_filename), category="error") flash(_(u"Failed to store file %s (Permission denied)." % saved_filename), category="error")
return redirect(url_for('index')) return redirect(url_for('index', _external=True))
try: try:
os.unlink(meta.file_path) os.unlink(meta.file_path)
except OSError, e: except OSError, e: