mirror of
https://github.com/logos-co/open-law.git
synced 2025-02-10 22:06:46 +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
|
"**/.venv/*/**": true
|
||||||
},
|
},
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
|
"backref",
|
||||||
"bookname",
|
"bookname",
|
||||||
"Btns",
|
"Btns",
|
||||||
"CLEANR",
|
"CLEANR",
|
||||||
|
@ -5,11 +5,27 @@ from app import models as m, db
|
|||||||
from app import schema as s
|
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(
|
def create_breadcrumbs(
|
||||||
book_id: int,
|
book_id: int,
|
||||||
collection_path: tuple[int],
|
collection_path: tuple[int],
|
||||||
section_id: int = 0,
|
section_id: int = 0,
|
||||||
interpretation_id: int = 0,
|
interpretation_id: int = 0,
|
||||||
|
collection_id: int = 0,
|
||||||
) -> list[s.BreadCrumb]:
|
) -> list[s.BreadCrumb]:
|
||||||
"""
|
"""
|
||||||
How breadcrumbs look like:
|
How breadcrumbs look like:
|
||||||
@ -52,28 +68,12 @@ def create_breadcrumbs(
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
for index, collection_id in enumerate(collection_path):
|
collections_crumbs = []
|
||||||
if collection_id is None:
|
|
||||||
continue
|
|
||||||
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
collection: m.Collection = db.session.get(m.Collection, collection_id)
|
||||||
if index == 0:
|
create_collections_breadcrumb(collections_crumbs, collection)
|
||||||
crumples += [
|
crumples += collections_crumbs.reverse()
|
||||||
s.BreadCrumb(
|
|
||||||
type=s.BreadCrumbType.Collection,
|
|
||||||
url="",
|
|
||||||
label=collection.label,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
elif index == 1:
|
|
||||||
crumples += [
|
|
||||||
s.BreadCrumb(
|
|
||||||
type=s.BreadCrumbType.Section,
|
|
||||||
url="",
|
|
||||||
label=collection.label,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
if section_id and collection_path:
|
if section_id and collection_id:
|
||||||
section: m.Section = db.session.get(m.Section, section_id)
|
section: m.Section = db.session.get(m.Section, section_id)
|
||||||
crumples += [
|
crumples += [
|
||||||
s.BreadCrumb(
|
s.BreadCrumb(
|
||||||
@ -81,10 +81,6 @@ def create_breadcrumbs(
|
|||||||
url=url_for(
|
url=url_for(
|
||||||
"book.interpretation_view",
|
"book.interpretation_view",
|
||||||
book_id=book_id,
|
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,
|
section_id=section_id,
|
||||||
),
|
),
|
||||||
label=section.label,
|
label=section.label,
|
||||||
|
@ -41,10 +41,7 @@ def interpretation_view(
|
|||||||
# FIXME breadcrumbs
|
# FIXME breadcrumbs
|
||||||
# breadcrumbs = create_breadcrumbs(
|
# breadcrumbs = create_breadcrumbs(
|
||||||
# book_id=book_id,
|
# book_id=book_id,
|
||||||
# collection_path=(
|
# collection_path=(section.collection.id,),
|
||||||
# collection_id,
|
|
||||||
# sub_collection_id,
|
|
||||||
# ),
|
|
||||||
# section_id=section_id,
|
# section_id=section_id,
|
||||||
# )
|
# )
|
||||||
return render_template(
|
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))
|
return redirect(url_for("book.collection_view", book_id=book_id))
|
||||||
|
|
||||||
# FIXME
|
# FIXME
|
||||||
# breadcrumbs = create_breadcrumbs(
|
breadcrumbs = create_breadcrumbs(
|
||||||
# book_id=book_id,
|
book_id=book_id,
|
||||||
# collection_path=(
|
collection_path=(interpretation.section.collection.id,),
|
||||||
# collection_id,
|
section_id=interpretation.section.id,
|
||||||
# sub_collection_id,
|
interpretation_id=interpretation.id,
|
||||||
# ),
|
_collection_id=interpretation.section.collection.id,
|
||||||
# section_id=section_id,
|
)
|
||||||
# interpretation_id=interpretation.id,
|
|
||||||
# )
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"book/qa_view.html",
|
"book/qa_view.html",
|
||||||
book=book,
|
book=book,
|
||||||
section=interpretation.section,
|
section=interpretation.section,
|
||||||
interpretation=interpretation,
|
interpretation=interpretation,
|
||||||
breadcrumbs=[],
|
breadcrumbs=breadcrumbs,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user