Ejemplo n.º 1
0
def book_get(limit):
    current_group = utils.get_current_group()

    if not current_group.book_view:
        return flask.Response(status=403, response='no permission')

    books = Book.query().order(-Book.added_date).fetch(limit)

    results = [{book.key.id(): book.to_dict()} for book in books]

    return results
Ejemplo n.º 2
0
def book_id_get(id):
    current_group = utils.get_current_group()

    if not current_group.book_view:
        return flask.Response(status=403, response='no permission')

    selected_book = ndb.Key(Book, id.lower()).get()

    if selected_book:
        return {selected_book.key.id(): selected_book.to_dict()}
    else:
        return flask.Response(status=404, response='not found')
Ejemplo n.º 3
0
def book_id_post(id, book):
    current_group = utils.get_current_group()

    if not current_group.book_edit:
        return flask.Response(status=403, response='no permission')

    if not (len(id) == 13 and id.isdigit()):
        return flask.Response(status=400, response='id must be 13 digits integer')

    if isinstance(book_id_get(id), dict):
        return flask.Response(status=400, response='already exists')

    new_book = Book(id=id)
    new_book.title = book['title']
    new_book.authors = book['authors']

    new_book.put()

    return {id: new_book.to_dict()}