diff --git a/tildes/tildes/resources/group.py b/tildes/tildes/resources/group.py index 5d35ba7..3bde070 100644 --- a/tildes/tildes/resources/group.py +++ b/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) diff --git a/tildes/tildes/templates/group_wiki_page.jinja2 b/tildes/tildes/templates/group_wiki_page.jinja2 index 340c26c..e29afa2 100644 --- a/tildes/tildes/templates/group_wiki_page.jinja2 +++ b/tildes/tildes/templates/group_wiki_page.jinja2 @@ -20,7 +20,7 @@ {% for folder in page.folders %} {% endfor %}