mirror of
https://github.com/logos-co/open-law.git
synced 2025-02-10 13:57:17 +00:00
start refactor breadcrumbs
This commit is contained in:
parent
dadb02338b
commit
d6c55661dc
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -11,6 +11,7 @@
|
||||
"**/.venv/*/**": true
|
||||
},
|
||||
"cSpell.words": [
|
||||
"backref",
|
||||
"bookname",
|
||||
"Btns",
|
||||
"CLEANR",
|
||||
|
@ -5,11 +5,27 @@ from app import models as m, db
|
||||
from app import schema as s
|
||||
|
||||
|
||||
def create_collections_breadcrumb(
|
||||
bread_crumbs: list[s.BreadCrumb], collection: m.Collection
|
||||
) -> list[s.BreadCrumb]:
|
||||
bread_crumbs += [
|
||||
s.BreadCrumb(
|
||||
type=s.BreadCrumbType.Collection,
|
||||
url="",
|
||||
label=collection.label,
|
||||
)
|
||||
]
|
||||
|
||||
if collection.parent and not collection.parent.is_root:
|
||||
create_collections_breadcrumb(bread_crumbs, collection.parent)
|
||||
|
||||
|
||||
def create_breadcrumbs(
|
||||
book_id: int,
|
||||
collection_path: tuple[int],
|
||||
section_id: int = 0,
|
||||
interpretation_id: int = 0,
|
||||
collection_id: int = 0,
|
||||
) -> list[s.BreadCrumb]:
|
||||
"""
|
||||
How breadcrumbs look like:
|
||||
@ -52,28 +68,12 @@ def create_breadcrumbs(
|
||||
)
|
||||
]
|
||||
|
||||
for index, collection_id in enumerate(collection_path):
|
||||
if collection_id is None:
|
||||
continue
|
||||
collections_crumbs = []
|
||||
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
||||
if index == 0:
|
||||
crumples += [
|
||||
s.BreadCrumb(
|
||||
type=s.BreadCrumbType.Collection,
|
||||
url="",
|
||||
label=collection.label,
|
||||
)
|
||||
]
|
||||
elif index == 1:
|
||||
crumples += [
|
||||
s.BreadCrumb(
|
||||
type=s.BreadCrumbType.Section,
|
||||
url="",
|
||||
label=collection.label,
|
||||
)
|
||||
]
|
||||
create_collections_breadcrumb(collections_crumbs, collection)
|
||||
crumples += collections_crumbs.reverse()
|
||||
|
||||
if section_id and collection_path:
|
||||
if section_id and collection_id:
|
||||
section: m.Section = db.session.get(m.Section, section_id)
|
||||
crumples += [
|
||||
s.BreadCrumb(
|
||||
@ -81,10 +81,6 @@ def create_breadcrumbs(
|
||||
url=url_for(
|
||||
"book.interpretation_view",
|
||||
book_id=book_id,
|
||||
collection_id=collection_path[0],
|
||||
sub_collection_id=collection_path[-1]
|
||||
if len(collection_path) == 2
|
||||
else collection_path[0],
|
||||
section_id=section_id,
|
||||
),
|
||||
label=section.label,
|
||||
|
@ -41,10 +41,7 @@ def interpretation_view(
|
||||
# FIXME breadcrumbs
|
||||
# breadcrumbs = create_breadcrumbs(
|
||||
# book_id=book_id,
|
||||
# collection_path=(
|
||||
# collection_id,
|
||||
# sub_collection_id,
|
||||
# ),
|
||||
# collection_path=(section.collection.id,),
|
||||
# section_id=section_id,
|
||||
# )
|
||||
return render_template(
|
||||
@ -192,19 +189,17 @@ def qa_view(book_id: int, interpretation_id: int):
|
||||
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||
|
||||
# FIXME
|
||||
# breadcrumbs = create_breadcrumbs(
|
||||
# book_id=book_id,
|
||||
# collection_path=(
|
||||
# collection_id,
|
||||
# sub_collection_id,
|
||||
# ),
|
||||
# section_id=section_id,
|
||||
# interpretation_id=interpretation.id,
|
||||
# )
|
||||
breadcrumbs = create_breadcrumbs(
|
||||
book_id=book_id,
|
||||
collection_path=(interpretation.section.collection.id,),
|
||||
section_id=interpretation.section.id,
|
||||
interpretation_id=interpretation.id,
|
||||
_collection_id=interpretation.section.collection.id,
|
||||
)
|
||||
return render_template(
|
||||
"book/qa_view.html",
|
||||
book=book,
|
||||
section=interpretation.section,
|
||||
interpretation=interpretation,
|
||||
breadcrumbs=[],
|
||||
breadcrumbs=breadcrumbs,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user