Merge pull request #36 from Simple2B/svyat/fix/breadcrumbs

fix breadcrumbs links
This commit is contained in:
Svyatoslav Artymovych 2023-05-09 17:53:11 +03:00 committed by GitHub
commit f5d72db39b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 63 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ node_modules/
.env .env
*.pyc *.pyc
/*.sqlite3 /*.sqlite3
.DS_Store

15
.vscode/settings.json vendored
View File

@ -26,8 +26,19 @@
"wsgi", "wsgi",
"wtforms" "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.pytestEnabled": true,
"python.testing.unittestEnabled": false, "python.testing.unittestEnabled": false,
"python.testing.pytestArgs": ["tests"] "python.testing.pytestArgs": [
"tests"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
} }

View File

@ -52,10 +52,11 @@ def create_breadcrumbs(
) )
] ]
for collection_id in collection_path: for index, collection_id in enumerate(collection_path):
if collection_id is None: if collection_id is None:
continue continue
collection: m.Collection = db.session.get(m.Collection, collection_id) collection: m.Collection = db.session.get(m.Collection, collection_id)
if index == 0:
crumples += [ crumples += [
s.BreadCrumb( s.BreadCrumb(
type=s.BreadCrumbType.Collection, type=s.BreadCrumbType.Collection,
@ -67,9 +68,7 @@ def create_breadcrumbs(
label=collection.label, label=collection.label,
) )
] ]
if section_id and collection_path: elif index == 1:
section: m.Section = db.session.get(m.Section, section_id)
if len(collection_path) == 2:
crumples += [ crumples += [
s.BreadCrumb( s.BreadCrumb(
type=s.BreadCrumbType.Section, type=s.BreadCrumbType.Section,
@ -79,18 +78,23 @@ def create_breadcrumbs(
collection_id=collection_path[0], collection_id=collection_path[0],
sub_collection_id=collection_path[-1], sub_collection_id=collection_path[-1],
), ),
label=section.label, label=collection.label,
) )
] ]
else:
if section_id and collection_path:
section: m.Section = db.session.get(m.Section, section_id)
crumples += [ crumples += [
s.BreadCrumb( s.BreadCrumb(
type=s.BreadCrumbType.Section, type=s.BreadCrumbType.Section,
url=url_for( url=url_for(
"book.section_view", "book.interpretation_view",
book_id=book_id, book_id=book_id,
collection_id=collection_path[0], collection_id=collection_path[0],
sub_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, label=section.label,
) )
@ -99,30 +103,18 @@ def create_breadcrumbs(
interpretation: m.Interpretation = db.session.get( interpretation: m.Interpretation = db.session.get(
m.Interpretation, interpretation_id m.Interpretation, interpretation_id
) )
if len(collection_path) == 2:
crumples += [ crumples += [
s.BreadCrumb( s.BreadCrumb(
type=s.BreadCrumbType.Interpretation, type=s.BreadCrumbType.Interpretation,
url=url_for( url=url_for(
"book.interpretation_view", "book.qa_view",
book_id=book_id, book_id=book_id,
collection_id=collection_path[0], collection_id=collection_path[0],
sub_collection_id=collection_path[-1], sub_collection_id=collection_path[-1]
section_id=section_id, if len(collection_path) == 2
), else collection_path[0],
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, section_id=section_id,
interpretation_id=interpretation_id,
), ),
label=interpretation.label, label=interpretation.label,
) )

View File

@ -4,7 +4,7 @@
{% for breadcrumb in breadcrumbs %} {% for breadcrumb in breadcrumbs %}
<li class="inline-flex items-center"> <li class="inline-flex items-center">
{% if not loop.index==breadcrumbs|length %} {% if not loop.index==breadcrumbs|length %}
<a href="{{ breadcrumb.url }}" class="inline-flex items-center text-sm truncate w-24 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white"> <a href="{{ breadcrumb.url }}" class="inline-flex items-center text-sm truncate w-30 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white">
{% else %} {% else %}
<span class="inline-flex items-center text-sm truncate w-40 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white"> <span class="inline-flex items-center text-sm truncate w-40 font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white">
{% endif %} {% endif %}
@ -16,7 +16,7 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="flex-shrink-0 w-4 h-4 mr-2 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white"><path stroke-linecap="round" stroke-linejoin="round" d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25" /> </svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="flex-shrink-0 w-4 h-4 mr-2 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white"><path stroke-linecap="round" stroke-linejoin="round" d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25" /> </svg>
{% endif %} {% endif %}
<!-- prettier-ignore --> <!-- prettier-ignore -->
<span class="truncate">{{ breadcrumb.label }}</span> <span class="truncate select-none">{{ breadcrumb.label }}</span>
{% if not loop.index==breadcrumbs|length %} {% if not loop.index==breadcrumbs|length %}
</a> </a>
{% else %} {% else %}

View File

@ -3,4 +3,4 @@
max-line-length = 120 max-line-length = 120
;exclude = tests/* ;exclude = tests/*
;max-complexity = 10 ;max-complexity = 10
exclude = .git,__pycache__,.venv/,migrations/ exclude = .git,__pycache__,.venv/,migrations/,node_modules