series view now orders books in series - still does not deal with series in series
This commit is contained in:
28
main.py
28
main.py
@@ -25,11 +25,6 @@ from rating import Rating, RatingForm, RatingSchema
|
||||
from loan import Loan, LoanForm, LoanSchema
|
||||
from series import Series, SeriesForm, SeriesSchema
|
||||
|
||||
# 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
|
||||
|
||||
####################################### CLASSES / DB model #######################################
|
||||
book_author_link = db.Table('book_author_link', db.Model.metadata,
|
||||
db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
|
||||
@@ -51,10 +46,21 @@ class Book_Loan_Link(db.Model):
|
||||
book_id = db.Column(db.Integer, db.ForeignKey('book.id'), unique=True, nullable=False, primary_key=True)
|
||||
loan_id = db.Column(db.Integer, db.ForeignKey('loan.id'), unique=True, nullable=False, primary_key=True)
|
||||
|
||||
def __repr__(self):
|
||||
return "<book_id: {}, loan_id: {}>".format(self.book_id, self.loan_id)
|
||||
|
||||
class Book_Series_Link(db.Model):
|
||||
__tablename__ = "book_series_link"
|
||||
book_id = db.Column(db.Integer, db.ForeignKey('book.id'), unique=True, nullable=False, primary_key=True)
|
||||
series_id = db.Column(db.Integer, db.ForeignKey('series.id'), unique=True, nullable=False, primary_key=True)
|
||||
book_num = db.Column(db.Integer)
|
||||
|
||||
def __repr__(self):
|
||||
return "<book_id: {}, series_id: {}, book_num: {}>".format(self.book_id, self.series_id, self.book_num)
|
||||
|
||||
def SeriesBookNum(series_id, book_id):
|
||||
bsl=Book_Series_Link.query.filter( Book_Series_Link.book_id==book_id, Book_Series_Link.series_id==series_id ).all()
|
||||
return bsl[0].book_num
|
||||
|
||||
class Book_Sub_Book_Link(db.Model):
|
||||
__tablename__ = "book_sub_book_link"
|
||||
@@ -92,6 +98,9 @@ class Book(db.Model):
|
||||
class Book_Sub_Book_LinkSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta: model = Book_Sub_Book_Link
|
||||
|
||||
class Book_Series_LinkSchema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta: model = Book_Series_Link
|
||||
|
||||
# Note not ordering this in the code below as, I can't work out how to use
|
||||
# jinja2 to iterate over orderedDict - seems it doesnt support it?
|
||||
# so I just hacked a list of keys in book.html
|
||||
@@ -100,6 +109,7 @@ class BookSchema(ma.SQLAlchemyAutoSchema):
|
||||
publisher = ma.Nested(PublisherSchema, many=True)
|
||||
genre = ma.Nested(GenreSchema, many=True)
|
||||
loan = ma.Nested(LoanSchema, many=True)
|
||||
series = ma.Nested(Book_Series_LinkSchema, many=True)
|
||||
parent_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True)
|
||||
child_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True)
|
||||
class Meta: model = Book
|
||||
@@ -122,6 +132,12 @@ class BookForm(FlaskForm):
|
||||
blurb = TextAreaField('Blurb:')
|
||||
|
||||
|
||||
# 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['SeriesBookNum'] = SeriesBookNum
|
||||
|
||||
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
|
||||
book_schema = BookSchema()
|
||||
books_schema = BookSchema(many=True)
|
||||
@@ -149,7 +165,7 @@ def books_for_loan(id):
|
||||
@app.route("/books_for_series/<id>", methods=["GET"])
|
||||
def books_for_series(id):
|
||||
books = Book.query.join(Book_Series_Link).filter(Book_Series_Link.series_id==id).order_by(Book.id).all()
|
||||
return render_template("books_for_series.html", books=books)
|
||||
return render_template("books_for_series.html", books=books, series_id=id)
|
||||
|
||||
@app.route("/book/<id>", methods=["GET"])
|
||||
def book(id):
|
||||
|
||||
Reference in New Issue
Block a user