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 store_book_metadata(library_id, book_id, sno): """Store books metadata for caching purposes""" redis = redis_py.Redis() book_metadata = bridge.book_info(library_id, book_id) redis_key3 = keys.redis_key3 book_key = "%s:%s:%s" % (redis_key3, library_id, book_id) metadata_key = book_key + ":meta_data" sno_key = book_key + ":sno" redis_py.set(metadata_key, json.dumps(book_metadata), True) redis_py.set(sno_key, json.dumps(sno), True) library_url_key = book_key + ":library_url" redis.expire(library_url_key, 60 * 60 * 60)