open-law/app/views/home.py

50 lines
1.4 KiB
Python
Raw Normal View History

2023-04-21 11:40:20 +00:00
from flask import (
Blueprint,
render_template,
)
2023-05-12 06:55:10 +00:00
from sqlalchemy import and_
from app import models as m, db
2023-05-26 13:56:04 +00:00
from app.logger import log
2023-04-21 11:40:20 +00:00
bp = Blueprint("home", __name__, url_prefix="/home")
@bp.route("/", methods=["GET"])
def get_all():
2023-05-26 13:56:04 +00:00
log(log.INFO, "Create query for home page for books")
2023-05-12 09:00:54 +00:00
books: m.Book = (
m.Book.query.filter_by(is_deleted=False).order_by(m.Book.id).limit(5)
2023-05-18 15:12:41 +00:00
).all()
2023-05-26 13:56:04 +00:00
log(log.INFO, "Create query for home page for interpretations")
2023-05-12 06:55:10 +00:00
interpretations = (
db.session.query(
m.Interpretation,
)
.filter(
and_(
m.Section.id == m.Interpretation.section_id,
m.Collection.id == m.Section.collection_id,
m.BookVersion.id == m.Section.version_id,
m.Book.id == m.BookVersion.book_id,
2023-05-17 15:01:39 +00:00
m.Book.is_deleted == False, # noqa: E712
m.BookVersion.is_deleted == False, # noqa: E712
m.Interpretation.is_deleted == False, # noqa: E712
m.Section.is_deleted == False, # noqa: E712
m.Collection.is_deleted == False, # noqa: E712
2023-05-12 06:55:10 +00:00
)
)
.order_by(m.Interpretation.created_at.desc())
.limit(5)
.all()
)
2023-05-26 13:56:04 +00:00
log(log.INFO, "Returning data to front end")
2023-04-21 11:40:20 +00:00
return render_template(
"home/index.html",
2023-04-27 12:40:48 +00:00
books=books,
2023-05-12 06:55:10 +00:00
interpretations=interpretations,
2023-04-21 11:40:20 +00:00
)