diff MoinMoin/items/__init__.py @ 1938:b8cfcf3bb9aa namespaces

fix initials computation for NAME being a list, move sort/upper/lower code to method
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 03 Feb 2013 16:05:21 +0100
parents 483dfd7fc86a
children ac5c618b96ca
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Sun Feb 03 15:23:59 2013 +0100
+++ b/MoinMoin/items/__init__.py	Sun Feb 03 16:05:21 2013 +0100
@@ -577,10 +577,24 @@
 
     index_template = 'index.html'
 
-    def name_initial(self, subitems):
-        prefixlen = len(self.subitems_prefix)
-        initials = [(item.meta[NAME][prefixlen]) for item in subitems]  # XXX BROKEN - this is a list of names now
-        return initials
+    def name_initial(self, subitems, uppercase=False, lowercase=False):
+        """
+        return a sorted list of first characters of subitem names,
+        optionally all uppercased or lowercased.
+        """
+        prefix = self.subitems_prefix
+        prefixlen = len(prefix)
+        initials = set()
+        for item in subitems:
+            for name in item.meta[NAME]:
+                if name.startswith(prefix):
+                    initial = name[prefixlen]
+                    if uppercase:
+                        initial = initial.upper()
+                    elif lowercase:
+                        initial = initial.lower()
+                    initials.add(initial)
+        return sorted(list(initials))
 
     delete_template = 'delete.html'
     destroy_template = 'destroy.html'