changeset 484:19b257c0e102

code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
author Akash Sinha <akash2607@gmail.com>
date Sat, 09 Jul 2011 00:11:02 +0530
parents 4307261bac75
children 3a3aea61aa1b
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/items/_tests/test_Item.py
diffstat 3 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Fri Jul 08 17:15:53 2011 +0530
+++ b/MoinMoin/apps/frontend/views.py	Sat Jul 09 00:11:02 2011 +0530
@@ -478,23 +478,14 @@
         abort(403)
     index = item.flat_index()
 
-    index_more_links = []
-    all_item_index = item.get_index()
-    all_item_text = "\n".join(item_info[1] for item_info in all_item_index)
-    for fullname, relname, contenttype in index:
-        hassubitem = False
-        subitem_name_re = u"%s/" % re.escape(relname)
-        regex = re.compile(subitem_name_re, re.UNICODE)
-        if regex.search(all_item_text):
-            hassubitem = True
-        index_more_links.append((fullname, relname, contenttype, hassubitem))
-    index_more_links.sort()
+    detailed_index = item.get_detailed_index(index)
+    detailed_index.sort()
     split_char = u'/'
     item_names = item_name.split(split_char)
 
     return render_template(item.index_template,
                            item=item, item_name=item_name,
-                           index=index_more_links,
+                           index=detailed_index,
                            item_names=item_names
                           )
 
--- a/MoinMoin/items/__init__.py	Fri Jul 08 17:15:53 2011 +0530
+++ b/MoinMoin/items/__init__.py	Sat Jul 09 00:11:02 2011 +0530
@@ -591,6 +591,20 @@
 
     index_template = 'index.html'
 
+    def get_detailed_index(self, index):
+        """ appends a flag in the index of items indicating that the parent has sub items """
+        detailed_index = []
+        all_item_index = self.get_index()
+        all_item_text = "\n".join(item_info[1] for item_info in all_item_index)
+        for fullname, relname, contenttype in index:
+            hassubitem = False
+            subitem_name_re = u"%s/" % re.escape(relname)
+            regex = re.compile(subitem_name_re, re.UNICODE)
+            if regex.search(all_item_text):
+                hassubitem = True
+            detailed_index.append((fullname, relname, contenttype, hassubitem))
+        return detailed_index
+
     def name_initial(self, names=None):
         initials = [(name[1][0])
                    for name in names]
--- a/MoinMoin/items/_tests/test_Item.py	Fri Jul 08 17:15:53 2011 +0530
+++ b/MoinMoin/items/_tests/test_Item.py	Sat Jul 09 00:11:02 2011 +0530
@@ -82,7 +82,7 @@
     def testIndex(self):
         # create a toplevel and some sub-items
         basename = u'Foo'
-        for name in ['', '/ab', '/cd/ef', '/gh', '/ij/kl', ]:
+        for name in ['', '/ab', '/cd/ef', '/gh', '/ij', '/ij/kl', ]:
             item = Item.create(basename + name)
             item._save({CONTENTTYPE: 'text/plain;charset=utf-8'}, "foo")
 
@@ -92,12 +92,19 @@
         assert index == [(u'Foo/ab', u'ab', 'text/plain;charset=utf-8'),
                          (u'Foo/cd/ef', u'cd/ef', 'text/plain;charset=utf-8'),
                          (u'Foo/gh', u'gh', 'text/plain;charset=utf-8'),
+                         (u'Foo/ij', u'ij', 'text/plain;charset=utf-8'),
                          (u'Foo/ij/kl', u'ij/kl', 'text/plain;charset=utf-8'),
                         ]
         flat_index = baseitem.flat_index()
         assert flat_index == [(u'Foo/ab', u'ab', 'text/plain;charset=utf-8'),
                               (u'Foo/gh', u'gh', 'text/plain;charset=utf-8'),
+                              (u'Foo/ij', u'ij', 'text/plain;charset=utf-8'),
                              ]
+        detailed_index = baseitem.get_detailed_index(baseitem.flat_index())
+        assert detailed_index == [(u'Foo/ab', u'ab', 'text/plain;charset=utf-8', False),
+                                  (u'Foo/gh', u'gh', 'text/plain;charset=utf-8', False),
+                                  (u'Foo/ij', u'ij', 'text/plain;charset=utf-8', True),
+                                 ]
 
 
 class TestTarItems(object):