Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

created get_latest_version function to return highest version for

sorting in getItemsBySections and getItemsByAudiencesAndSections
  • Loading branch information...
commit 757b44e3f094042c8e34389221b245e66b57384b 1 parent 64f2f19
@lukebrannon lukebrannon authored
Showing with 14 additions and 9 deletions.
  1. +14 −9 Products/PloneHelpCenter/browser/phcfolder.py
View
23 Products/PloneHelpCenter/browser/phcfolder.py
@@ -29,7 +29,17 @@ def _sectionCmp(a, b):
else:
return 1
-
+def get_latest_version(item):
+ """ returns the latest version number """
+
+ listVersions = list(item.getVersions)
+
+ if len(listVersions) > 0:
+ listVersions.sort()
+ return listVersions[-1]
+ else:
+ return 0
+
class HelpCenterFolderView(BrowserView):
""" support for HelpCenter container templates """
@@ -72,7 +82,7 @@ def getItemsBySection(self, section, **kwargs):
continue
res.append(brain)
return res
-
+
def getItemsBySections(self, **kwargs):
"""Get all items to list, by section only. Returns a list of dicts:
@@ -112,9 +122,7 @@ def getItemsBySections(self, **kwargs):
# sort inside sections
for j in sections:
- #j['items'].sort(_sectionCmp)
- j['items'].sort(key=lambda x: x.getVersions)
- j['items'].reverse()
+ j['items'].sort(key=get_latest_version, reverse=True)
return sections
@@ -207,13 +215,10 @@ def getItemsByAudiencesAndSections(self, **kwargs):
# sort inside sections
for a in audiences:
for s in a['sections']:
- s['items'].sort(key=lambda x: x.getVersions)
- s['items'].reverse()
- #s['items'].sort(_sectionCmp)
+ s['items'].sort(key=get_latest_version, reverse=True)
return audiences
-
@memoize
def getSectionsToList(self, **kwargs):
"""Sections that have at least one listable item. Note that this does
Please sign in to comment.
Something went wrong with that request. Please try again.