def bootstrapTestDB(db): """ Takes an created SQLAlchemy db and bootstraps the tables with dummy data """ books_copy, authors_copy = deepcopy(books), deepcopy(authors) # load authors for author_data in authors: db.session.add(Author.author_from_dict(**author_data)) db.session.commit() # load genres for book_data in books_copy: for genre in book_data['genres']: g = Genre.query.filter_by(name=genre).first() if not g: db.session.add(Genre(genre)) db.session.flush() db.session.commit() # load books for book_data in books_copy: book_data['genres'] = [ Genre.query.filter_by(name=genre_item).first() for genre_item in book_data['genres'] ] book_data['author'] = Author.query.filter_by(name=book_data['author']).first() db.session.add(Book.book_from_dict(**book_data)) # commit the changes db.session.commit() #load users for author_data in authors_copy: author = Author.query.filter_by(name=author_data['name']).first() db.session.add(AppUser(author_data['user_href'], author)) db.session.commit()
def bootstrapTestDB(db): """ Takes an created SQLAlchemy db and bootstraps the tables with dummy data """ books_copy, authors_copy = deepcopy(books), deepcopy(authors) # load authors for author_data in authors: db.session.add(Author.author_from_dict(**author_data)) db.session.commit() # load genres for book_data in books_copy: for genre in book_data['genres']: g = Genre.query.filter_by(name=genre).first() if not g: db.session.add(Genre(genre)) db.session.flush() db.session.commit() # load books for book_data in books_copy: book_data['genres'] = [ Genre.query.filter_by(name=genre_item).first() for genre_item in book_data['genres'] ] book_data['author'] = Author.query.filter_by( name=book_data['author']).first() db.session.add(Book.book_from_dict(**book_data)) # commit the changes db.session.commit() #load users for author_data in authors_copy: author = Author.query.filter_by(name=author_data['name']).first() db.session.add( AppUser(stormpathUserHash(author_data['user_href']), author_data['user_href'], author)) db.session.commit()
def settings(): user_id = user.get_id() app_user = AppUser.query.get(stormpathUserHash(user_id)) if request.method == 'GET': return render_template('author_settings.html', author=app_user.author) if not app_user.is_author: author = Author.author_from_dict(**request.form.to_dict()) db.session.add(author) db.session.commit() app_user.become_author(author) ## TODO Handle edit author attributes """ if app_user.is_author: author_name = request.form.get('author_name') if author_name != app_user.author.name: app_user.author.update_name(author_name) """ return render_template('author_settings.html', author=app_user.author)