def add(): if request.method == 'POST': data = request.form.to_dict(flat=True) # If an image was uploaded, update the data to point to the new image. image_url = upload_image_file(request.files.get('image')) if image_url: data['imageUrl'] = image_url # If the user is logged in, associate their profile with the new book. if 'profile' in session: data['createdBy'] = session['profile']['name'] data['createdById'] = session['profile']['email'] book = get_model().create(data) # [START enqueue] q = tasks.get_books_queue() q.enqueue(tasks.process_book, book['id']) # [END enqueue] return redirect(url_for('.view', id=book['id'])) return render_template("form.html", action="Add", book={})
def add(): if request.method == 'POST': data = request.form.to_dict(flat=True) # If an image was uploaded, update the data to point to the new image. image_url = upload_image_file(request.files.get('image')) if image_url: data['imageUrl'] = image_url # If the user is logged in, associate their profile with the new book. if 'profile' in session: data['createdBy'] = session['profile']['displayName'] data['createdById'] = session['profile']['id'] book = get_model().create(data) # [START enqueue] q = tasks.get_books_queue() q.enqueue(tasks.process_book, book['id']) # [END enqueue] return redirect(url_for('.view', id=book['id'])) return render_template("form.html", action="Add", book={})
def delete(id): book = get_model().read(id) image_url = book.get('imageUrl') get_model().delete(id) # Async job to delete book image in GCS. if image_url: image_name = image_url.split('/')[-1] q = tasks.get_books_queue() q.enqueue(tasks.delete_book_image, image_name) return redirect(url_for('.list'))
def edit(id): book = get_model().read(id) if request.method == 'POST': data = request.form.to_dict(flat=True) image_url = upload_image_file(request.files.get('image')) if image_url: data['imageUrl'] = image_url book = get_model().update(data, id) q = tasks.get_books_queue() q.enqueue(tasks.process_book, book['id']) return redirect(url_for('.view', id=book['id'])) return render_template("form.html", action="Edit", book=book)