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 loan import Loan, LoanForm, LoanSchema
|
||||||
from series import Series, SeriesForm, SeriesSchema
|
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 #######################################
|
####################################### CLASSES / DB model #######################################
|
||||||
book_author_link = db.Table('book_author_link', db.Model.metadata,
|
book_author_link = db.Table('book_author_link', db.Model.metadata,
|
||||||
db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
|
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)
|
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)
|
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):
|
class Book_Series_Link(db.Model):
|
||||||
__tablename__ = "book_series_link"
|
__tablename__ = "book_series_link"
|
||||||
book_id = db.Column(db.Integer, db.ForeignKey('book.id'), unique=True, nullable=False, primary_key=True)
|
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)
|
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):
|
class Book_Sub_Book_Link(db.Model):
|
||||||
__tablename__ = "book_sub_book_link"
|
__tablename__ = "book_sub_book_link"
|
||||||
@@ -92,6 +98,9 @@ class Book(db.Model):
|
|||||||
class Book_Sub_Book_LinkSchema(ma.SQLAlchemyAutoSchema):
|
class Book_Sub_Book_LinkSchema(ma.SQLAlchemyAutoSchema):
|
||||||
class Meta: model = Book_Sub_Book_Link
|
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
|
# 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?
|
# jinja2 to iterate over orderedDict - seems it doesnt support it?
|
||||||
# so I just hacked a list of keys in book.html
|
# 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)
|
publisher = ma.Nested(PublisherSchema, many=True)
|
||||||
genre = ma.Nested(GenreSchema, many=True)
|
genre = ma.Nested(GenreSchema, many=True)
|
||||||
loan = ma.Nested(LoanSchema, 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)
|
parent_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True)
|
||||||
child_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True)
|
child_ref = ma.Nested(Book_Sub_Book_LinkSchema, many=True)
|
||||||
class Meta: model = Book
|
class Meta: model = Book
|
||||||
@@ -122,6 +132,12 @@ class BookForm(FlaskForm):
|
|||||||
blurb = TextAreaField('Blurb:')
|
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?)
|
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
|
||||||
book_schema = BookSchema()
|
book_schema = BookSchema()
|
||||||
books_schema = BookSchema(many=True)
|
books_schema = BookSchema(many=True)
|
||||||
@@ -149,7 +165,7 @@ def books_for_loan(id):
|
|||||||
@app.route("/books_for_series/<id>", methods=["GET"])
|
@app.route("/books_for_series/<id>", methods=["GET"])
|
||||||
def books_for_series(id):
|
def books_for_series(id):
|
||||||
books = Book.query.join(Book_Series_Link).filter(Book_Series_Link.series_id==id).order_by(Book.id).all()
|
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"])
|
@app.route("/book/<id>", methods=["GET"])
|
||||||
def book(id):
|
def book(id):
|
||||||
|
|||||||
@@ -7,12 +7,20 @@
|
|||||||
{% for book in books %}
|
{% for book in books %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if book.sub_book_num is defined %}
|
{% if book.sub_book_num is defined %}
|
||||||
<td data-sort="{{book.parent_id}}.{{book.sub_book_num}}"><a href="/book/{{book.id}}"> {{book.title}}</a></td>
|
<td><a href="/book/{{book.id}}"> {{book.title}}</a></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td data-sort="{{book.id}}"><a href="/book/{{book.id}}">{{book.title}}</a></td>
|
<td><a href="/book/{{book.id}}">{{book.title}}</a></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>not yet:</a></td>
|
<td data-sort="{{series_id, SeriesBookNum( series_id, book.id )}}">{{ SeriesBookNum( series_id, book.id ) }}
|
||||||
|
</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('#book_table').DataTable( { "paging": false, "searching": false, "info": false, "order": [[1, 'asc']] } );
|
||||||
|
} );
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user