-
Last sections
+ {% for interpretation in interpretations %}
+
+
+
+
+ {% if interpretation.user_id != current_user.id %}
+
+ {% endif %}
+
+
+ {{ interpretation.vote_count }}
+
+
+ {% if interpretation.user_id != current_user.id %}
+
+ {% endif %}
+
+
+
-
+
+ {% set local_breadcrumbs = interpretation.section.breadcrumbs_path %}
+ {% include 'book/local_breadcrumbs_navigation.html'%}
+
{{ interpretation.section.label }}
+
+
+
{{ interpretation.text|safe }}
+
+
+
+
+ Interpretation by
+ {{interpretation.user.username}} on {{interpretation.created_at.strftime('%B %d, %Y')}}
+
+
+
+
+
+
+
+
{{interpretation.active_comments | length}}
+
+
+
+
+
+
+
+ {% endfor %}
diff --git a/app/views/book.py b/app/views/book.py
index 04a2a47..cd13157 100644
--- a/app/views/book.py
+++ b/app/views/book.py
@@ -147,6 +147,17 @@ def collection_view(book_id: int):
)
+@bp.route("//statistics", methods=["GET"])
+def statistic_view(book_id: int):
+ book = db.session.get(m.Book, book_id)
+ if not book or book.is_deleted:
+ log(log.WARNING, "Book with id [%s] not found", book_id)
+ flash("Book not found", "danger")
+ return redirect(url_for("book.my_library"))
+ else:
+ return render_template("book/stat.html", book=book)
+
+
@bp.route("///subcollections", methods=["GET"])
def sub_collection_view(book_id: int, collection_id: int):
book: m.Book = db.session.get(m.Book, book_id)
diff --git a/app/views/home.py b/app/views/home.py
index a95d49e..18c6445 100644
--- a/app/views/home.py
+++ b/app/views/home.py
@@ -2,9 +2,8 @@ from flask import (
Blueprint,
render_template,
)
-from flask_login import current_user
-
-from app import models as m
+from sqlalchemy import and_
+from app import models as m, db
bp = Blueprint("home", __name__, url_prefix="/home")
@@ -12,16 +11,30 @@ bp = Blueprint("home", __name__, url_prefix="/home")
@bp.route("/", methods=["GET"])
def get_all():
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)
- last_user_sections = []
- if current_user.is_authenticated:
- last_user_sections: m.Section = m.Section.query.order_by(
- m.Section.created_at
- ).limit(5)
+ 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,
+ m.Book.is_deleted.is_(False),
+ m.BookVersion.is_deleted.is_(False),
+ m.Interpretation.is_deleted.is_(False),
+ m.Section.is_deleted.is_(False),
+ m.Collection.is_deleted.is_(False),
+ )
+ )
+ .order_by(m.Interpretation.created_at.desc())
+ .limit(5)
+ .all()
+ )
return render_template(
"home/index.html",
books=books,
- sections=sections,
- last_user_sections=last_user_sections,
+ interpretations=interpretations,
)
diff --git a/tests/test_book.py b/tests/test_book.py
index 2b86df9..20fcd78 100644
--- a/tests/test_book.py
+++ b/tests/test_book.py
@@ -1101,3 +1101,113 @@ def test_access_to_settings_page(client: FlaskClient):
assert response.status_code == 200
assert b"You are not owner of this book!" in response.data
+
+
+def test_interpretation_in_home_last_inter_section(
+ client: FlaskClient, runner: FlaskCliRunner
+):
+ _, user = login(client)
+ user: m.User
+
+ # add dummmy data
+ runner.invoke(args=["db-populate"])
+
+ book: m.Book = db.session.get(m.Book, 1)
+ book.user_id = user.id
+ book.save()
+
+ leaf_collection: m.Collection = m.Collection(
+ label="Test Leaf Collection #1 Label",
+ version_id=book.last_version.id,
+ is_leaf=True,
+ parent_id=book.last_version.root_collection.id,
+ ).save()
+ section_in_collection: m.Section = m.Section(
+ label="Test Section in Collection #1 Label",
+ about="Test Section in Collection #1 About",
+ collection_id=leaf_collection.id,
+ version_id=book.last_version.id,
+ ).save()
+
+ collection: m.Collection = m.Collection(
+ label="Test Collection #1 Label", version_id=book.last_version.id
+ ).save()
+ sub_collection: m.Collection = m.Collection(
+ label="Test SubCollection #1 Label",
+ version_id=book.last_version.id,
+ parent_id=collection.id,
+ is_leaf=True,
+ ).save()
+ section_in_subcollection: m.Section = m.Section(
+ label="Test Section in Subcollection #1 Label",
+ about="Test Section in Subcollection #1 About",
+ collection_id=sub_collection.id,
+ version_id=book.last_version.id,
+ ).save()
+
+ label_1 = "Test Interpretation #1 Label"
+ text_1 = "Test Interpretation #1 Text"
+
+ response: Response = client.post(
+ f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/create_interpretation",
+ data=dict(section_id=section_in_subcollection.id, label=label_1, text=text_1),
+ follow_redirects=True,
+ )
+
+ assert response.status_code == 200
+ interpretation: m.Interpretation = m.Interpretation.query.filter_by(
+ label=label_1, section_id=section_in_subcollection.id
+ ).first()
+ assert interpretation
+ assert interpretation.section_id == section_in_subcollection.id
+ assert not interpretation.comments
+
+ response: Response = client.post(
+ f"/book/{book.id}/{leaf_collection.id}/{section_in_collection.id}/create_interpretation",
+ data=dict(section_id=section_in_collection.id, label=label_1, text=text_1),
+ follow_redirects=True,
+ )
+
+ assert response.status_code == 200
+ interpretation: m.Interpretation = m.Interpretation.query.filter_by(
+ label=label_1, section_id=section_in_collection.id
+ ).first()
+ assert interpretation
+ assert interpretation.section_id == section_in_collection.id
+ assert not interpretation.comments
+
+ response: Response = client.post(
+ f"/book/{book.id}/{collection.id}/999/create_section",
+ data=dict(collection_id=999, label=label_1, text=text_1),
+ follow_redirects=True,
+ )
+
+ assert response.status_code == 200
+ assert b"Subcollection not found" in response.data
+
+ response: Response = client.post(
+ f"/book/{book.id}/{leaf_collection.id}/999/create_interpretation",
+ data=dict(collection_id=999, label=label_1, text=text_1),
+ follow_redirects=True,
+ )
+
+ assert response.status_code == 200
+ assert b"Section not found" in response.data
+
+ response: Response = client.post(
+ f"/book/{book.id}/{collection.id}/{sub_collection.id}/888/create_interpretation",
+ data=dict(collection_id=999, label=label_1, text=text_1),
+ follow_redirects=True,
+ )
+
+ assert response.status_code == 200
+ assert b"Section not found" in response.data
+
+ response: Response = client.get(
+ f"/home",
+ follow_redirects=True,
+ )
+
+ assert response
+ assert response.status_code == 200
+ assert str.encode(text_1) in response.data