From 51787a241278d6ac86d86b3cc15a6d4c33583038 Mon Sep 17 00:00:00 2001 From: Deimos Date: Thu, 13 Jun 2019 10:34:11 -0600 Subject: [PATCH] Move some of the wiki index logic to views This still isn't great, but a little cleaner. --- tildes/tildes/templates/group_wiki_page.jinja2 | 4 +--- tildes/tildes/templates/topic_listing.jinja2 | 4 +--- tildes/tildes/views/group_wiki_page.py | 9 ++++++++- tildes/tildes/views/topic.py | 11 ++++++++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tildes/tildes/templates/group_wiki_page.jinja2 b/tildes/tildes/templates/group_wiki_page.jinja2 index 48f6042..39ccc9e 100644 --- a/tildes/tildes/templates/group_wiki_page.jinja2 +++ b/tildes/tildes/templates/group_wiki_page.jinja2 @@ -42,13 +42,11 @@ diff --git a/tildes/tildes/templates/topic_listing.jinja2 b/tildes/tildes/templates/topic_listing.jinja2 index 703c2f3..1721270 100644 --- a/tildes/tildes/templates/topic_listing.jinja2 +++ b/tildes/tildes/templates/topic_listing.jinja2 @@ -228,13 +228,11 @@ diff --git a/tildes/tildes/views/group_wiki_page.py b/tildes/tildes/views/group_wiki_page.py index f0ae625..fd4f3a9 100644 --- a/tildes/tildes/views/group_wiki_page.py +++ b/tildes/tildes/views/group_wiki_page.py @@ -40,7 +40,14 @@ def get_group_wiki_page(request: Request) -> dict: .all() ) - return {"page": page, "page_list": page_list} + # remove the index from the page list, we'll output it separately + if any(page.slug == "index" for page in page_list): + has_index_page = True + page_list = [page for page in page_list if page.slug != "index"] + else: + has_index_page = False + + return {"page": page, "page_list": page_list, "has_index_page": has_index_page} @view_config( diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index e02b217..ab4f29b 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -106,7 +106,7 @@ def get_group_topics( unfiltered: bool, ) -> dict: """Get a listing of topics in the group.""" - # pylint: disable=too-many-arguments, too-many-branches + # pylint: disable=too-many-arguments, too-many-branches, too-many-locals if request.matched_route.name == "home": # on the home page, include topics from the user's subscribed groups # (or all groups, if logged-out) @@ -176,8 +176,16 @@ def get_group_topics( .order_by(GroupWikiPage.slug) .all() ) + + # remove the index from the page list, we'll output it separately + if any(page.slug == "index" for page in wiki_pages): + wiki_has_index = True + wiki_pages = [page for page in wiki_pages if page.slug != "index"] + else: + wiki_has_index = False else: wiki_pages = None + wiki_has_index = False return { "group": request.context, @@ -195,6 +203,7 @@ def get_group_topics( "tag": tag, "unfiltered": unfiltered, "wiki_pages": wiki_pages, + "wiki_has_index": wiki_has_index, }