def dashboard(msg=None): user = auth.get_logged_in_user() try: books = Books.select().where( Books.ownership == user).order_by(Books.id.desc()) return object_list("book_list.html", books, 'book_list') except Books.DoesNotExist: return render_template("dashboard.html", msg=msg) return render_template("dashboard.html", msg=msg)
def del_book(id): exists = Books.select().filter(id=id).exists() if not exists: return jsonify( {"message": "Can't find book with id - `{id}`".format(id=id)}), 404 Books.delete().where(Books.id == id).execute() return jsonify({}), 204
def endpoint(id=None): if request.method == 'GET': if id: return jsonify(model_to_dict(Books.get(Books.id == id))) else: bookList = [] for book in Books.select(): bookList.append(model_to_dict(book)) return jsonify(bookList) if request.method == 'POST': new_book = dict_to_model(Books, request.get_json()) new_book.save() return jsonify({"success": True})
def getlist_book(): return jsonify(bookSchema.dump(list(Books.select()), many=True).data), 200
def api_author_books(aid): books_id = set( Stories.select(fn.Distinct( Stories.book)).where(Stories.author == aid).tuples()) rs = Books.select().where(Books.id << books_id).dicts() return jsonify({'result': list(rs)})