示例#1
0
def update_book(book_id):
    book = books.get(book_id)
    if not book:
        abort(404)
    if not request.json:
        abort(400)
    data = request.json
    if any([
            'title' in data and not isinstance(data.get('title'), str),
            'author' in data and not isinstance(data.get('author'), str),
            'year' in data and not isinstance(data.get('year'), int),
            'description' in data
            and not isinstance(data.get('description'), str), 'done' in data
            and not isinstance(data.get('done'), bool)
    ]):
        abort(400)
    book = {
        'title': data.get('title', book['title']),
        'author': data.get('author', book['author']),
        'year': data.get('year', book['year']),
        'description': data.get('description', book['description']),
        'done': data.get('done', book['done']),
        'id': book['id']
    }
    books.update(book_id, book)
    return jsonify({'book': book})
示例#2
0
def update_book(book_id):
    book = books.get(book_id)
    if not book:
        abort(404)
    if not request.json:
        abort(400)
    data = request.json
    if any([
        'title' in data and not isinstance(data.get('title'), str),
        'author' in data and not isinstance(data.get('author'), str),
        'genre' in data and not isinstance(data.get('genre'), str),
        'release_year' in data and not isinstance(data.get('release_year'), int),
        'series' in data and not isinstance(data.get('series'), str),
        'read' in data and not isinstance(data.get('read'), bool),
        'review' in data and not isinstance(data.get('review'), str)   
    ]):
        abort(400)
    book = {
        'title': data.get('title', book['title']),
        'author': data.get('author', book['author']),
        'genre': data.get('genre', book['genre']),
        'release_year': data.get('release_year', book['release_year']),
        'series': data.get('series', book['series']),
        'read': data.get('read', book['read']),
        'review': data.get('review', book['review'])
    }
    books.update(book_id, book)
    return jsonify({'book': book})
示例#3
0
def book_details(book_id):
    book = books.get(book_id - 1)
    form = BookForm(data=book)

    if request.method == "POST":
        if form.validate_on_submit():
            books.update(book_id - 1, form.data)
        return redirect(url_for("books_list"))
    return render_template("book.html", form=form, book_id=book_id)
示例#4
0
def update_book(book_id):
    book = books.get(book_id - 1)
    form = LibrForm(data=book)
    error = ""
    if request.method == "POST":
        if form.validate_on_submit():
            books.update(book_id - 1, form.data)
            books.save_all()
        return redirect(url_for("books_list"))

    return render_template("book_add.html",
                           form=form,
                           book_id=book_id,
                           error=error)
示例#5
0
def update_books(book_id):
    book = books.get(book_id)
    if book is None:
        abort(404)
    if request.json is None:
        abort(400)
    data = request.json
    if any([
            'title' in data and not isinstance(data.get('title'), str),
            'author' in data and not isinstance(data.get('author'), str),
            'description' in data
            and not isinstance(data.get('description'), str),
            'done' in data and not isinstance(data.get('done'), bool),
            'number_of_pages' in data
            and not isinstance(data.get('number_of_pages'), int),
    ]):
        abort(400)

    books.update(book_id, book)
    return jsonify({'book': book})
示例#6
0
def update_book(book_id):
    book = books.get(book_id)
    if not book:
        abort(404)
    if not request.json:
        abort(400)
    data = request.json
    if any([
        'id' in data and not isinstance(data.get('id'), int),
        'title' in data and not isinstance(data.get('title'), str),
        'author' in data and not isinstance(data.get('author'), str),
        'publishment_date' in data and not isinstance(data.get('publishment_date'), str),
        'description' in data and not isinstance(data.get('description'), str)
    ]):
        return make_response(jsonify({"errors": "All of Fields is required", 'status_code': 400}), 400)
    book = {
        'id': data.get('id', book['id']),
        'title': data.get('title', book['title']),
        'author': data.get('author', book['author']),
        'publishment_date': data.get('publishment_dater', book['publishment_date']),
        'description': data.get('description', book['description'])
    }
    books.update(book_id, book)
    return jsonify({'book': book})