From 257cbec86ea179ca48a80d9fc97cf1f9824a2551 Mon Sep 17 00:00:00 2001 From: Deimos Date: Sun, 11 Aug 2019 13:26:41 -0600 Subject: [PATCH] Wiki: find index pages in folders automatically Cancel that previous change, this is a better way of doing it. --- tildes/tildes/resources/group.py | 14 +++++++++++++- tildes/tildes/templates/group_wiki_page.jinja2 | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) 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 %}