changeset 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
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py
diffstat 2 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sun Feb 03 15:23:59 2013 +0100
+++ b/MoinMoin/apps/frontend/views.py	Sun Feb 03 16:05:21 2013 +0100
@@ -760,10 +760,7 @@
     selected_groups = form['contenttype'].value
     startswith = request.values.get("startswith")
 
-    initials = item.name_initial(item.get_subitem_revs())
-    initials = [initial.upper() for initial in initials]
-    initials = list(set(initials))
-    initials = sorted(initials)
+    initials = item.name_initial(item.get_subitem_revs(), uppercase=True)
 
     dirs, files = item.get_index(startswith, selected_groups)
     # index = sorted(index, key=lambda e: e.relname.lower())
--- 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'