From 2255d63b979ad1245cd3e288b9c308ec82c4c925 Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Tue, 9 May 2023 16:30:44 +0300 Subject: [PATCH 1/3] fix breadcrumbs links --- .vscode/settings.json | 17 ++- app/controllers/breadcrumbs.py | 106 ++++++++---------- .../book/breadcrumbs_navigation.html | 4 +- 3 files changed, 65 insertions(+), 62 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0d19073..ca25566 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,8 +25,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 425e70f..fb837ee 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 %} From ccd37e898a8552186da52e8ea370c3e0a7ab1369 Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Tue, 9 May 2023 16:34:42 +0300 Subject: [PATCH 2/3] tox.ini, .gitignore --- .gitignore | 1 + tox.ini | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/tox.ini b/tox.ini index ada0531..e46e628 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 \ No newline at end of file From 34a0ed9101e7353e45300e6f8504e4ee1514a5da Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Tue, 9 May 2023 16:36:29 +0300 Subject: [PATCH 3/3] eof eol --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index e46e628..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/,node_modules \ No newline at end of file +exclude = .git,__pycache__,.venv/,migrations/,node_modules