def seed_db(): """Seeds the database.""" db.session.add( Book( title= 'Effective DevOps: Building a Culture of Collaboration, Affinity, and Tooling at Scale', author='Jennifer Davis, Ryn Daniels', read=False, comment='very cool')) db.session.add( Book(title='Practical DevOps', author='Joakim Verona', read=False, comment='very cool')) db.session.add( Book(title='Site Reliability Engineering', author='Niall Murphy, Betsy Beyer, Chris Jones, Jennifer Petoff', read=False, comment='very cool')) db.session.add( Book(title='The DevOps HandBook', author='Gene Kim, Jez Humble, John Willis, and Patrick, Debois', read=False, comment='very cool')) db.session.add( Book( title= 'Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation', author='Jez Humble and David Farley', read=False, comment='very cool')) db.session.commit()
def seed_db(): """Seeds the database.""" db.session.add(Book(title='On the Road', author='Jack Kerouac', read=True)) db.session.add( Book(title='Harry Potter and the Philosopher\'s Stone', author='J. K. Rowling', read=False)) db.session.add( Book(title='Green Eggs and Ham', author='Dr. Seuss', read=True)) db.session.commit()
def post(self): post_data = request.get_json() response_object = { 'status': 'fail', 'message': 'Invalid payload.' } if not post_data: return response_object, 400 title = post_data.get('title') author = post_data.get('author') isbn = post_data.get('isbn') try: book = Book.query.filter_by(isbn=isbn).first() if not book: db.session.add(Book(title=title, author=author, isbn=isbn)) db.session.commit() response_object['status'] = 'success' response_object['message'] = f'{title} was added!' return response_object, 201 else: response_object['message'] = 'Sorry. That book already exists.' return response_object, 400 except exc.IntegrityError: db.session.rollback() return response_object, 400
def index(): if request.method == 'POST': title = request.form['title'] author = request.form['author'] isbn = request.form['isbn'] db.session.add(Book(title=title, author=author, isbn=isbn)) db.session.commit() books = Book.query.all() return render_template('index.html', books=books)
def seed_db(): """Seeds the database.""" db.session.add( Book(title='The Awakening', author='Kelley Armstrong', isbn='61662763')) db.session.add( Book(title='The Van Alen Legacy', author='Melissa de la Cruz', isbn='1423102266')) db.session.add( Book(title='Noughts & Crosses', author='Malorie Blackman', isbn='552555703')) db.session.add( Book(title='Lincoln in the Bardo', author='George Saunders', isbn='812995341')) db.session.commit()
def all_books(): response_object = {'status': 'success', 'container_id': os.uname()[1]} if request.method == 'POST': post_data = request.get_json() title = post_data.get('title') author = post_data.get('author') read = post_data.get('read') db.session.add(Book(title=title, author=author, read=read)) db.session.commit() response_object['message'] = 'Book added!' else: response_object['books'] = [ book.to_json() for book in Book.query.all() ] return jsonify(response_object)