Browse Source

Wiki: find index pages in folders automatically

Cancel that previous change, this is a better way of doing it.
merge-requests/76/merge
Deimos 5 years ago
parent
commit
257cbec86e
  1. 14
      tildes/tildes/resources/group.py
  2. 2
      tildes/tildes/templates/group_wiki_page.jinja2

14
tildes/tildes/resources/group.py

@ -4,7 +4,7 @@
"""Root factories for groups."""
from marshmallow.fields import String
from pyramid.httpexceptions import HTTPMovedPermanently
from pyramid.httpexceptions import HTTPMovedPermanently, HTTPNotFound
from pyramid.request import Request
from sqlalchemy_utils import Ltree
from webargs.pyramidparser import use_kwargs
@ -44,4 +44,16 @@ def group_wiki_page_by_path(request: Request, wiki_page_path: str) -> GroupWikiP
GroupWikiPage.group == group, GroupWikiPage.path == wiki_page_path
)
# try to return the page with the exact path, but catch if it doesn't exist
try:
return get_resource(request, query)
except HTTPNotFound:
pass
# if it didn't exist, try treating it as a folder and looking for an index page
wiki_page_path += "/index"
query = request.query(GroupWikiPage).filter(
GroupWikiPage.group == group, GroupWikiPage.path == wiki_page_path
)
return get_resource(request, query)

2
tildes/tildes/templates/group_wiki_page.jinja2

@ -20,7 +20,7 @@
</li>
{% for folder in page.folders %}
<li class="breadcrumb-item">
<a href="{{ request.route_url("group_wiki_page", group_path=page.group.path, wiki_page_path=folder~"/index") }}">{{ folder.name }}</a>
<a href="{{ request.route_url("group_wiki_page", group_path=page.group.path, wiki_page_path=folder|string) }}">{{ folder.name }}</a>
</li>
{% endfor %}
</ol>

Loading…
Cancel
Save