def edit_book(): """POST method for handling edit Books request.""" id = request.form["id"] name = request.form["name"] author_id = request.form["author_id"] Book.update_by_id(id, name, author_id) return Response(json.dumps({"ok": "true"}), mimetype="application/json")
def prepare_books_table(): """Render table with Books.""" row_data = Book.get_all() rows = [ {"id": el.get("id"), "cells": [el.get("name"), "%s %s" % (el.get("author_name"), el.get("author_surname"))]} for el in row_data ] table = {"headers": ["Name", "Author"], "rows": rows} return render_template("table.html", table=table)
def delete_book(): """POST method for handling delete Books request.""" id = request.form["id"] Book.delete_by_id(id) return Response(json.dumps({"ok": "true"}), mimetype="application/json")
def new_book(): """POST method for handling new Books request.""" name = request.form["name"] author_id = request.form["author_id"] id = Book.add_new(name, author_id) return Response(json.dumps({"id": id}), mimetype="application/json")