open-law/app/views/home.py

29 lines
736 B
Python
Raw Normal View History

2023-04-21 11:40:20 +00:00
from flask import (
Blueprint,
render_template,
)
2023-04-28 11:33:46 +00:00
from flask_login import current_user, login_required
2023-04-21 11:40:20 +00:00
2023-04-27 12:40:48 +00:00
from app import models as m
2023-04-21 11:40:20 +00:00
bp = Blueprint("home", __name__, url_prefix="/home")
@bp.route("/", methods=["GET"])
2023-04-28 11:33:46 +00:00
@login_required
2023-04-21 11:40:20 +00:00
def get_all():
2023-04-27 12:40:48 +00:00
books: m.Book = m.Book.query.order_by(m.Book.id).limit(5)
sections: m.Section = m.Section.query.order_by(m.Section.id).limit(5)
2023-04-28 12:28:41 +00:00
last_user_sections = []
2023-04-27 12:40:48 +00:00
if current_user.is_authenticated:
last_user_sections: m.Section = m.Section.query.order_by(
m.Section.created_at
).limit(5)
2023-04-21 11:40:20 +00:00
return render_template(
"home/index.html",
2023-04-27 12:40:48 +00:00
books=books,
sections=sections,
last_user_sections=last_user_sections,
2023-04-21 11:40:20 +00:00
)