diff --git a/.gitignore b/.gitignore index b2fa676..b6e9344 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ node_modules/ .env *.pyc /*.sqlite3 +.DS_Store \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 3620efc..1d2537d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,8 +26,19 @@ "wsgi", "wtforms" ], - "python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "*test.py"], + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "*test.py" + ], "python.testing.pytestEnabled": true, "python.testing.unittestEnabled": false, - "python.testing.pytestArgs": ["tests"] -} + "python.testing.pytestArgs": [ + "tests" + ], + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } +} \ No newline at end of file diff --git a/app/controllers/breadcrumbs.py b/app/controllers/breadcrumbs.py index 7875d4a..3a99392 100644 --- a/app/controllers/breadcrumbs.py +++ b/app/controllers/breadcrumbs.py @@ -52,24 +52,23 @@ def create_breadcrumbs( ) ] - for collection_id in collection_path: + for index, collection_id in enumerate(collection_path): if collection_id is None: continue collection: m.Collection = db.session.get(m.Collection, collection_id) - crumples += [ - s.BreadCrumb( - type=s.BreadCrumbType.Collection, - url=url_for( - "book.sub_collection_view", - book_id=book_id, - collection_id=collection_id, - ), - label=collection.label, - ) - ] - if section_id and collection_path: - section: m.Section = db.session.get(m.Section, section_id) - if len(collection_path) == 2: + if index == 0: + crumples += [ + s.BreadCrumb( + type=s.BreadCrumbType.Collection, + url=url_for( + "book.sub_collection_view", + book_id=book_id, + collection_id=collection_id, + ), + label=collection.label, + ) + ] + elif index == 1: crumples += [ s.BreadCrumb( type=s.BreadCrumbType.Section, @@ -79,53 +78,46 @@ def create_breadcrumbs( collection_id=collection_path[0], sub_collection_id=collection_path[-1], ), - label=section.label, - ) - ] - else: - crumples += [ - s.BreadCrumb( - type=s.BreadCrumbType.Section, - url=url_for( - "book.section_view", - book_id=book_id, - collection_id=collection_path[0], - sub_collection_id=collection_path[0], - ), - label=section.label, + label=collection.label, ) ] + + if section_id and collection_path: + section: m.Section = db.session.get(m.Section, section_id) + crumples += [ + s.BreadCrumb( + type=s.BreadCrumbType.Section, + 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, + ) + ] if interpretation_id: interpretation: m.Interpretation = db.session.get( m.Interpretation, interpretation_id ) - if len(collection_path) == 2: - crumples += [ - s.BreadCrumb( - type=s.BreadCrumbType.Interpretation, - url=url_for( - "book.interpretation_view", - book_id=book_id, - collection_id=collection_path[0], - sub_collection_id=collection_path[-1], - section_id=section_id, - ), - label=interpretation.label, - ) - ] - else: - crumples += [ - s.BreadCrumb( - type=s.BreadCrumbType.Interpretation, - url=url_for( - "book.interpretation_view", - book_id=book_id, - collection_id=collection_path[0], - sub_collection_id=collection_path[0], - section_id=section_id, - ), - label=interpretation.label, - ) - ] + crumples += [ + s.BreadCrumb( + type=s.BreadCrumbType.Interpretation, + url=url_for( + "book.qa_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, + interpretation_id=interpretation_id, + ), + label=interpretation.label, + ) + ] return crumples diff --git a/app/templates/book/breadcrumbs_navigation.html b/app/templates/book/breadcrumbs_navigation.html index 5656608..19b6e56 100644 --- a/app/templates/book/breadcrumbs_navigation.html +++ b/app/templates/book/breadcrumbs_navigation.html @@ -4,7 +4,7 @@ {% for breadcrumb in breadcrumbs %}
  • {% if not loop.index==breadcrumbs|length %} - + {% else %} {% endif %} @@ -16,7 +16,7 @@ {% endif %} - {{ breadcrumb.label }} + {{ breadcrumb.label }} {% if not loop.index==breadcrumbs|length %} {% else %} diff --git a/tox.ini b/tox.ini index ada0531..e8f8f61 100644 --- a/tox.ini +++ b/tox.ini @@ -3,4 +3,4 @@ max-line-length = 120 ;exclude = tests/* ;max-complexity = 10 -exclude = .git,__pycache__,.venv/,migrations/ \ No newline at end of file +exclude = .git,__pycache__,.venv/,migrations/,node_modules