now have a class to maintain the status, use that to set alert/message for owned, and redirect after create/update/delete owned -> owneds

This commit is contained in:
2020-12-05 11:00:53 +11:00
parent d61e830525
commit 5057e856be
3 changed files with 26 additions and 25 deletions

25
main.py
View File

@@ -4,7 +4,9 @@ from flask_marshmallow import Marshmallow
from flask_bootstrap import Bootstrap
from wtforms import SubmitField, StringField, HiddenField, SelectField, IntegerField, TextAreaField, validators
from flask_wtf import FlaskForm
from status import st, Status
####################################### Flask App globals #######################################
app = Flask(__name__)
### what is this value? I gather I should chagne it?
DB_URL = 'postgresql+psycopg2://ddp:NWNlfa01@127.0.0.1:5432/library'
@@ -15,6 +17,7 @@ db = SQLAlchemy(app)
ma = Marshmallow(app)
Bootstrap(app)
################################# Now, import non-book classes ###################################
from author import Author, AuthorForm, AuthorSchema, GetAuthors
from publisher import Publisher, PublisherForm, PublisherSchema, GetPublisherById
from genre import Genre, GenreForm, GenreSchema, GetGenres
@@ -173,16 +176,6 @@ class BookForm(FlaskForm):
delete = SubmitField('Delete' )
# allow jinja2 to call this python function
app.jinja_env.globals['GetCovertypeById'] = GetCovertypeById
app.jinja_env.globals['GetOwnedById'] = GetOwnedById
app.jinja_env.globals['GetConditionById'] = GetConditionById
app.jinja_env.globals['GetPublisherById'] = GetPublisherById
app.jinja_env.globals['SeriesBookNum'] = SeriesBookNum
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
book_schema = BookSchema()
################################# helper functions ###################################
def GetBookIdFromSeriesByBookNum( series_id, book_num ):
tmp_book = Book_Series_Link.query.filter(Book_Series_Link.series_id==series_id,Book_Series_Link.book_num==book_num).all()
@@ -199,6 +192,18 @@ def GetBookIdFromBookSubBookLinkByIdAndSubBookNum( book_id, sub_book_num ):
tmp_bsbl = Book_Sub_Book_Link.query.filter(Book_Sub_Book_Link.book_id==book_id, Book_Sub_Book_Link.sub_book_num==sub_book_num ).all()
return tmp_bsbl[0].sub_book_id
####################################### GLOBALS #######################################
# allow jinja2 to call this python function
app.jinja_env.globals['GetCovertypeById'] = GetCovertypeById
app.jinja_env.globals['GetOwnedById'] = GetOwnedById
app.jinja_env.globals['GetConditionById'] = GetConditionById
app.jinja_env.globals['GetPublisherById'] = GetPublisherById
app.jinja_env.globals['SeriesBookNum'] = SeriesBookNum
app.jinja_env.globals['ClearStatus'] = st.ClearMessage
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
book_schema = BookSchema()
####################################### ROUTES #######################################
@app.route("/books", methods=["GET"])
def books():