diff MoinMoin/items/__init__.py @ 486:b6149c732926

contenttype filtering added to global index page
author Akash Sinha <akash2607@gmail.com>
date Wed, 13 Jul 2011 04:57:51 +0530
parents 19b257c0e102
children 8462764f59d2
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Sat Jul 09 00:34:12 2011 +0530
+++ b/MoinMoin/items/__init__.py	Wed Jul 13 04:57:51 2011 +0530
@@ -19,6 +19,7 @@
 import tarfile
 import zipfile
 import tempfile
+import itertools
 from StringIO import StringIO
 from array import array
 
@@ -575,17 +576,36 @@
                  for item in item_iterator]
         return sorted(items)
 
-    def flat_index(self, startswith=None):
+    def flat_index(self, startswith=None, selected_groups=None):
+        """
+        creates an top level index of sub items of this item
+        if startswith is set, filtering is done on the basis of starting letter of item name
+        if selected_groups is set, items whose contentype belonging to the selected contenttype_groups, are filtered.
+        """
         index = self.get_index()
+        nonexistent_item = NonExistent(self)
+        if not selected_groups:
+            selected_groups = [gname for (gname, contenttypes) in nonexistent_item.contenttype_groups]
+
+        ctypes = [[ctype for ctype, clabel in contenttypes]
+                  for gname, contenttypes in nonexistent_item.contenttype_groups
+                  if gname in selected_groups]
+
+        ctypes_chain = itertools.chain(*ctypes)
+        selected_contenttypes = list(ctypes_chain)
+
         if startswith:
             startswith = (u'%s' % startswith, u'%s' % startswith.swapcase())
             index = [(fullname, relname, contenttype)
                      for fullname, relname, contenttype in index
-                     if u'/' not in relname and relname.startswith(startswith)]
+                     if u'/' not in relname
+                     and relname.startswith(startswith)
+                     and contenttype in selected_contenttypes]
         else:
             index = [(fullname, relname, contenttype)
                      for fullname, relname, contenttype in index
-                     if u'/' not in relname]
+                     if u'/' not in relname
+                     and contenttype in selected_contenttypes]
 
         return index