Browse Source

Move some of the wiki index logic to views

This still isn't great, but a little cleaner.
merge-requests/72/head
Deimos 6 years ago
parent
commit
51787a2412
  1. 4
      tildes/tildes/templates/group_wiki_page.jinja2
  2. 4
      tildes/tildes/templates/topic_listing.jinja2
  3. 9
      tildes/tildes/views/group_wiki_page.py
  4. 11
      tildes/tildes/views/topic.py

4
tildes/tildes/templates/group_wiki_page.jinja2

@ -42,13 +42,11 @@
<ul class="nav"> <ul class="nav">
<li>Page list</li> <li>Page list</li>
<ul class="nav"> <ul class="nav">
{% if page_list|selectattr("page_name", "eq", "index")|list %}
{% if has_index_page %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=page.group.path, wiki_page_slug="index") }}" class="text-bold">index</a></li> <li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=page.group.path, wiki_page_slug="index") }}" class="text-bold">index</a></li>
{% endif %} {% endif %}
{% for other_page in page_list %} {% for other_page in page_list %}
{% if other_page.page_name != "index" %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=other_page.group.path, wiki_page_slug=other_page.slug) }}">{{ other_page.page_name }}</a></li> <li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=other_page.group.path, wiki_page_slug=other_page.slug) }}">{{ other_page.page_name }}</a></li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
</ul> </ul>

4
tildes/tildes/templates/topic_listing.jinja2

@ -228,13 +228,11 @@
<ul class="nav"> <ul class="nav">
<li>Group wiki pages</li> <li>Group wiki pages</li>
<ul class="nav"> <ul class="nav">
{% if wiki_pages|selectattr("page_name", "eq", "index")|list %}
{% if wiki_has_index %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_slug="index") }}" class="text-bold">index</a></li> <li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_slug="index") }}" class="text-bold">index</a></li>
{% endif %} {% endif %}
{% for page in wiki_pages %} {% for page in wiki_pages %}
{% if page.page_name != "index" %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_slug=page.slug) }}">{{ page.page_name }}</a></li> <li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_slug=page.slug) }}">{{ page.page_name }}</a></li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
</ul> </ul>

9
tildes/tildes/views/group_wiki_page.py

@ -40,7 +40,14 @@ def get_group_wiki_page(request: Request) -> dict:
.all() .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( @view_config(

11
tildes/tildes/views/topic.py

@ -106,7 +106,7 @@ def get_group_topics(
unfiltered: bool, unfiltered: bool,
) -> dict: ) -> dict:
"""Get a listing of topics in the group.""" """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": if request.matched_route.name == "home":
# on the home page, include topics from the user's subscribed groups # on the home page, include topics from the user's subscribed groups
# (or all groups, if logged-out) # (or all groups, if logged-out)
@ -176,8 +176,16 @@ def get_group_topics(
.order_by(GroupWikiPage.slug) .order_by(GroupWikiPage.slug)
.all() .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: else:
wiki_pages = None wiki_pages = None
wiki_has_index = False
return { return {
"group": request.context, "group": request.context,
@ -195,6 +203,7 @@ def get_group_topics(
"tag": tag, "tag": tag,
"unfiltered": unfiltered, "unfiltered": unfiltered,
"wiki_pages": wiki_pages, "wiki_pages": wiki_pages,
"wiki_has_index": wiki_has_index,
} }

Loading…
Cancel
Save