Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Sorts the children pages on the homepage by A-Z
Browse files Browse the repository at this point in the history
Fixes #48.
  • Loading branch information
Denis Krienbühl committed Aug 31, 2015
1 parent 6488dcd commit 2d67931
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
Unreleased
~~~~~~~~~~

- Sorts the children pages on the homepage by A-Z as well.
[href]

- Includes the submitter e-mail address on the ticket view.
[href]

Expand Down
20 changes: 15 additions & 5 deletions onegov/town/views/homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from onegov.core.security import Public
from onegov.form import FormCollection
from onegov.libres import ResourceCollection
from onegov.page import PageCollection, Page
from onegov.people import PersonCollection
from onegov.town import _
from onegov.town.app import TownApp
Expand All @@ -21,18 +22,27 @@ def view_town(self, request):
session = request.app.session()
libres_context = request.app.libres_context
layout = DefaultLayout(self, request)

Tile = namedtuple('Tile', ['page', 'links', 'number'])

tiles = [
Tile(
pages = PageCollection(session)
children_query = pages.query().order_by(Page.title)

tiles = []
for ix, page in enumerate(layout.root_pages):

if page.type == 'topic':
children = children_query.filter(Page.parent_id == page.id)
children = children.limit(3).all()

tiles.append(Tile(
page=Link(page.title, request.link(page)),
number=ix + 1,
links=[
Link(c.title, request.link(c), classes=('tile-sub-link',))
for c in (page.children[:3] if page.type == 'topic' else [])
for c in children
]
) for ix, page in enumerate(layout.root_pages)
]
))

# the panels on the homepage are currently mostly place-holders, real
# links as well as translatable text is added every time we implement
Expand Down

0 comments on commit 2d67931

Please sign in to comment.