Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort setup items by translated title #97

Merged
merged 2 commits into from Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Changelog.rst
Expand Up @@ -9,6 +9,7 @@

**Changed**

- #97 Sort setup items by translated title
- #90 Integration for senaite.core 1.3
- #88 Refactored spotlight backend and added more columns to results table
- #87 Stay on current context when switching the language
Expand Down
13 changes: 10 additions & 3 deletions src/senaite/lims/browser/controlpanel/views/setupview.py
Expand Up @@ -7,6 +7,7 @@

import os

from bika.lims.utils import t
from plone.memoize.volatile import cache
from plone.memoize.volatile import store_on_context
from Products.Five.browser import BrowserView
Expand Down Expand Up @@ -76,9 +77,15 @@ def setupitems(self):
"query": api.get_path(self.setup),
"depth": 1,
},
"sort_on": "sortable_title",
"sort_order": "ascending"
}
items = api.search(query, "portal_catalog")
return filter(lambda item: not item.exclude_from_nav, items)
# filter out items
items = filter(lambda item: not item.exclude_from_nav, items)

# sort by (translated) title
def cmp_by_translated_title(brain1, brain2):
title1 = t(api.get_title(brain1))
title2 = t(api.get_title(brain2))
return cmp(title1, title2)

return sorted(items, cmp=cmp_by_translated_title)