From 6cd10b73788026400e284106a59cc919b86dd91a Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Mon, 24 Apr 2023 09:57:38 +0300 Subject: [PATCH] book creation --- app/__init__.py | 4 +- app/forms/__init__.py | 1 + app/forms/book.py | 8 ++++ app/templates/books/add_book_modal.html | 7 +-- app/templates/sidebar.html | 2 +- app/views/__init__.py | 2 +- app/views/{books.py => book.py} | 23 +++++----- tests/test_book.py | 60 +++++++++++++++++++++++++ 8 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 app/forms/book.py rename app/views/{books.py => book.py} (60%) create mode 100644 tests/test_book.py diff --git a/app/__init__.py b/app/__init__.py index b708c77..c02a6d8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -21,7 +21,7 @@ def create_app(environment="development"): main_blueprint, auth_blueprint, user_blueprint, - books_blueprint, + book_blueprint, home_blueprint, ) from app.models import ( @@ -48,7 +48,7 @@ def create_app(environment="development"): app.register_blueprint(auth_blueprint) app.register_blueprint(main_blueprint) app.register_blueprint(user_blueprint) - app.register_blueprint(books_blueprint) + app.register_blueprint(book_blueprint) app.register_blueprint(home_blueprint) # Set up flask login. diff --git a/app/forms/__init__.py b/app/forms/__init__.py index 535edbf..c98a5d5 100644 --- a/app/forms/__init__.py +++ b/app/forms/__init__.py @@ -1,3 +1,4 @@ # flake8: noqa F401 from .auth import LoginForm from .user import UserForm, NewUserForm +from .book import CreateBookForm diff --git a/app/forms/book.py b/app/forms/book.py new file mode 100644 index 0000000..fecb7b4 --- /dev/null +++ b/app/forms/book.py @@ -0,0 +1,8 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField +from wtforms.validators import DataRequired, Length + + +class CreateBookForm(FlaskForm): + label = StringField("Label", [DataRequired(), Length(6, 1024)]) + submit = SubmitField("Add new book") diff --git a/app/templates/books/add_book_modal.html b/app/templates/books/add_book_modal.html index a97f0d0..b908bd0 100644 --- a/app/templates/books/add_book_modal.html +++ b/app/templates/books/add_book_modal.html @@ -3,7 +3,8 @@