in invoice-processing-pipeline/reviewer/main.py [0:0]
def approve_selected_invoices():
# Will be making changes in DB and Cloud Storage, so prepare clients
db = firestore.Client()
gcs = storage.Client()
bucket = gcs.get_bucket(BUCKET_NAME)
# Checked boxes will show up as keys in the Flask request form object
for blob_name in request.form.keys():
# Set the state to Approved in Firestore
docref = db.collection("invoices").document(blob_name)
info = docref.get().to_dict()
info["state"] = "Approved"
docref.set(info)
# Rename storage blob from PROCESSED_PREFIX to APPROVED_PREFIX
blob = bucket.get_blob(f"{PROCESSED_PREFIX}{blob_name}")
bucket.rename_blob(blob, f"{APPROVED_PREFIX}{blob_name}")
# Show the home page again to users
return redirect("/")