def index(): subtitle = "Transfer books to Internet Archive" form = UploadForm(request.form) if request.method == "POST": if form.validate(): book_id = html_escape(form.book_id.data) email = html_escape(form.email.data) if form.email.data not in (None, "") else "" book = bridge.fields(form.library_id.data, book_id, email) book_id = book.Id if book.Id not in (None, "") else book_id redis = redis_py.Redis() redis_key3 = keys.redis_key3 book_key = "%s:%s:%s" % (redis_key3, form.library_id.data, book_id) library_url_key = book_key + ":library_url" redis_py.set(library_url_key, form.book_id.data, True) redis.expire(library_url_key, 60 * 15) verification_status_no = book.verify_fields() if verification_status_no != 0: flash(error_msg(verification_status_no, book)) return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) else: if redundant_request(book) == True: flash(error_msg(50)) return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) book_info = bridge.book_info(form.library_id.data, book_id) if isinstance(book_info, (int, long, float, complex)): flash(error_msg(book_info)) return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) confirm_resp = make_response(minify(render_template("confirm.html", book_info=book_info, form=form))) uuid = urandom(32).encode("hex") confirm_resp.set_cookie("bub_session", uuid) store_request(book, uuid) return confirm_resp return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) else: return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form)
def index(): subtitle = "Transfer books to Internet Archive" form = UploadForm(request.form) if request.method == 'POST': if form.validate(): book_id = html_escape(form.book_id.data) email = html_escape( form.email.data) if form.email.data not in (None, "") else "" book = bridge.fields(form.library_id.data, book_id, email) book_id = book.Id if book.Id not in (None, "") else book_id redis = redis_py.Redis() redis_key3 = keys.redis_key3 book_key = "%s:%s:%s" % (redis_key3, form.library_id.data, book_id) library_url_key = book_key + ":library_url" redis_py.set(library_url_key, form.book_id.data, True) redis.expire(library_url_key, 60 * 15) verification_status_no = book.verify_fields() if verification_status_no != 0: flash(error_msg(verification_status_no, book)) return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) else: if redundant_request(book) == True: flash(error_msg(50)) return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) book_info = bridge.book_info(form.library_id.data, book_id) if isinstance(book_info, (int, long, float, complex)): flash(error_msg(book_info)) return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) confirm_resp = make_response( minify( render_template("confirm.html", book_info=book_info, form=form))) uuid = urandom(32).encode("hex") confirm_resp.set_cookie('bub_session', uuid) store_request(book, uuid) return confirm_resp return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form) else: return render_template("index.html", subtitle=subtitle, libraries=libraries, form=form)
def render_template(text, **kwargs): return minify(rt(text, **kwargs), css=False)