Esempio n. 1
0
def edit_author():
    """POST method for handling edit Author request."""
    id = request.form["id"]
    name = request.form["name"]
    surname = request.form["surname"]
    Author.update_by_id(id, name, surname)
    return Response(json.dumps({"ok": "true"}), mimetype="application/json")
Esempio n. 2
0
def delete_author():
    """POST method for handling delete Author request."""
    id = request.form["id"]
    Author.delete_by_id(id)
    return Response(json.dumps({"ok": "true"}), mimetype="application/json")
Esempio n. 3
0
def prepare_authors_select():
    """Render Select-Box wirh authors."""
    data = Author.get_all()
    options = [{"id": el.get("id"), "text": "%s %s" % (el.get("name"), el.get("surname"))} for el in data]
    select = {"id": "book_author", "options": options}
    return render_template("select.html", select=select)
Esempio n. 4
0
def new_author():
    """POST method for handling new Author request."""
    name = request.form["name"]
    surname = request.form["surname"]
    id = Author.add_new(name, surname)
    return Response(json.dumps({"id": id}), mimetype="application/json")
Esempio n. 5
0
def prepare_authors_table():
    """Render table with authors."""
    row_data = Author.get_all()
    rows = [{"id": el.get("id"), "cells": [el.get("name"), el.get("surname")]} for el in row_data]
    table = {"headers": ["Name", "Surname"], "rows": rows}
    return render_template("table.html", table=table)