示例#1
0
def create_book():
    book_list = book_repository.select_all()
    for book in book_list:
        if book.author.name == request.form["author"]:
            new_book = Book(request.form["title"], book.author)
            book_repository.save(new_book)
            return
        else:
            new_author = Author(request.form["author"])
            author_repository.save(new_author)
            new_book = Book(request.form["title"], new_author)
            book_repository.save(new_book)

    return redirect("/books")
示例#2
0
from models.book import Book
from models.author import Author
import repositories.book_repository as book_repository
import repositories.author_repository as author_repository

author_1 = Author("Dan", "Brown")
author_repository.save(author_1)

author_2 = Author("J.K.", "Rowling")
author_repository.save(author_2)

book_1 = Book("davinci-code", "mystery", "penguin", author_1)
book_repository.save(book_1)
示例#3
0
import pdb
from models.book import Book
from models.author import Author

import repositories.book_repository as book_repository
import repositories.author_repository as author_repository

book_repository.delete_all()
author_repository.delete_all()

author1 = Author("Terry", "Pratchett")
author_repository.save(author1)
author2 = Author("David", "Ascher")
author_repository.save(author2)

book_1 = Book("Colour of Magic", "Fantasy", "Colin Smythe", author1)
book_repository.save(book_1)

book_2 = Book("The Light Fantastic", "Fantasy", "Colin Smythe", author1)
book_repository.save(book_2)

book_3 = Book("Learning Python", "Education", "O' Reilly", author2)
book_repository.save(book_3)
示例#4
0
import pdb
from models.book import Book
from models.author import Author

import repositories.book_repository as book_repository
import repositories.author_repository as author_repository

book_repository.delete_all()
author_repository.delete_all()

author1 = Author("Robin", "Hobb")
author_repository.save(author1)
author2 = Author("Philip", "Pullman")
author_repository.save(author2)
author3 = Author("Isaac", "Asimov")
author_repository.save(author3)
author4 = Author("Markus", "Zusak")
author_repository.save(author4)
author5 = Author("Peter", "May")
author_repository.save(author5)

book_1 = Book("Ship of Magic", "Fantasy", "HarperCollins", author1)
book_repository.save(book_1)
book_2 = Book("The Mad Ship", "Fantasy", "HarperCollins", author1)
book_repository.save(book_2)
book_3 = Book("Ship of Destiny", "Fantasy", "HarperCollins", author1)
book_repository.save(book_3)
book_4 = Book("Northern Lights", "Fantasy", "Scholastic", author2)
book_repository.save(book_4)
book_5 = Book("The Subtle Knife", "Fantasy", "Scholastic", author2)
book_repository.save(book_5)
示例#5
0
# Import modules
import pdb
from models.author import Author
from models.book import Book
import repositories.author_repository as author_repo
import repositories.book_repository as book_repo

# Add some data to db

author1 = Author('JK', 'Rowling')
author2 = Author('George', 'Orwell')
author3 = Author('Charles', 'Dickens')

author_repo.save(author1)
author_repo.save(author2)
author_repo.save(author3)

book1 = Book('Harry Potter and the Goblet of Fire', '08/07/2000', author1)
book_repo.save(book1)

book2 = Book('Harry Potter and the Chamber of Secrets', '02/07/1998', author1)
book_repo.save(book2)

book3 = Book('1948', '08/06/1949', author2)
book_repo.save(book3)

book4 = Book('Christmas Carol', '01/01/1843', author3)
book_repo.save(book4)