diff --git a/app/__init__.py b/app/__init__.py index 7a5e1b3..ce5d073 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -23,6 +23,7 @@ def create_app(environment="development"): user_blueprint, book_blueprint, home_blueprint, + section_blueprint, ) from app.models import ( User, @@ -50,6 +51,7 @@ def create_app(environment="development"): app.register_blueprint(user_blueprint) app.register_blueprint(book_blueprint) app.register_blueprint(home_blueprint) + app.register_blueprint(section_blueprint) # Set up flask login. @login_manager.user_loader diff --git a/app/models/section.py b/app/models/section.py index 29a500d..627d6fc 100644 --- a/app/models/section.py +++ b/app/models/section.py @@ -32,5 +32,20 @@ class Section(BaseModel): path += self.label return path + @property + def book_id(self): + _book_id = self.version.book_id + return _book_id + + @property + def sub_collection_id(self): + parent = self.collection + grand_parent = parent.parent + if grand_parent.is_root: + _sub_collection_id = parent.id + else: + _sub_collection_id = grand_parent.id + return _sub_collection_id + def __repr__(self): return f"<{self.id}: {self.label}>" diff --git a/app/templates/section/all.html b/app/templates/section/all.html new file mode 100644 index 0000000..d057694 --- /dev/null +++ b/app/templates/section/all.html @@ -0,0 +1,125 @@ + +{% extends 'base.html' %} +{% block content %} + +
+ +
+ +

Sections

+
+ +
+ {% for section in sections %} + + +
+
+
+ +

{{ section.path }}

+
+ + + + +

55

+
+ + + + + +

55

+
+
+
+
+
+
+ + {% endfor %} +
+ + {% if page.pages > 1 %} +
+ +
+ {% endif %} +
+ + +{% endblock %} + +{% block scripts %} +{% endblock %} diff --git a/app/views/__init__.py b/app/views/__init__.py index 7751f4f..9c6c52e 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -4,3 +4,4 @@ from .main import main_blueprint from .user import bp as user_blueprint from .book import bp as book_blueprint from .home import bp as home_blueprint +from .section import bp as section_blueprint diff --git a/app/views/section.py b/app/views/section.py new file mode 100644 index 0000000..b4feaa1 --- /dev/null +++ b/app/views/section.py @@ -0,0 +1,29 @@ +from flask import ( + Blueprint, + render_template, + request, +) + +from app.controllers import create_pagination +from app import models as m + + +bp = Blueprint("section", __name__, url_prefix="/section") + + +@bp.route("/all", methods=["GET"]) +def get_all(): + q = request.args.get("q", type=str, default=None) + section: m.Section = m.Section.query.order_by(m.Section.id) + if q: + section = section.filter(m.Section.label.like(f"{q}")) + + pagination = create_pagination(total=section.count()) + + return render_template( + "section/all.html", + sections=section.paginate(page=pagination.page, per_page=pagination.per_page), + page=pagination, + search_query=q, + all_books=True, + )