def create_book(name, **kwargs): owner_id = get_current_user_id() if not owner_id: return False description = kwargs.get('description') genres_ids = kwargs.get('genres_ids') or [] cover_image_url = kwargs.get('cover_image_url') page_count = kwargs.get('page_count') author_name = kwargs.get('author_name') year = kwargs.get('year') book = Book(name=name, owner_id=owner_id) book.description = description book.cover_image_url = cover_image_url book.page_count = page_count book.author_name = author_name book.year = year genres = [] for id in genres_ids: g = get_genre_by_id(id) if g: genres.append(g) book.genres = genres session.add(book) session.commit() return book