changeset 1046:97f917f7c8ba namespaces

Item.get_index() will set proper context in all subitems, so that right name is chosen in case there are multiple names Implements proper recursion rename for multiple names
author Luis Henrique Fagundes <lhfagundes@gmail.com>
date Tue, 01 Nov 2011 12:24:16 -0200
parents 900263d0e393
children 3480b8036b48
files MoinMoin/items/__init__.py MoinMoin/storage/middleware/indexing.py MoinMoin/storage/middleware/protecting.py
diffstat 3 files changed, 30 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Tue Nov 01 12:21:54 2011 -0200
+++ b/MoinMoin/items/__init__.py	Tue Nov 01 12:24:16 2011 -0200
@@ -533,10 +533,13 @@
             query = Term(WIKINAME, app.cfg.interwikiname)
         # We only want the sub-item part of the item names, not the whole item objects.
         prefix_len = len(prefix)
-        revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
-        items = [(rev.name, rev.name[prefix_len:], rev.meta[CONTENTTYPE])
-                 for rev in revs]
-        return items
+        revs = flaskg.storage.search(query, limit=None)
+        items = []
+        for rev in revs:
+            rev.set_context(self.name)
+            items.append((rev.name, rev.name[prefix_len:], rev.meta[CONTENTTYPE]))
+
+        return sorted(items, key=lambda item: item[0])
 
     def _connect_levels(self, index):
         new_index = []
--- a/MoinMoin/storage/middleware/indexing.py	Tue Nov 01 12:21:54 2011 -0200
+++ b/MoinMoin/storage/middleware/indexing.py	Tue Nov 01 12:24:16 2011 -0200
@@ -853,7 +853,7 @@
     """
     An existing revision (exists in the backend).
     """
-    def __init__(self, item, revid, doc=None):
+    def __init__(self, item, revid, doc=None, name=None):
         is_current = revid == CURRENT
         if doc is None:
             if is_current:
@@ -872,21 +872,32 @@
         self._doc = doc
         self.meta = Meta(self, self._doc)
         self._data = None
+        if name and name in self.names:
+            self._name = name
+        else:
+            self._name = None
         # Note: this does not immediately raise a KeyError for non-existing revs any more
         # If you access data or meta, it will, though.
 
     @property
+    def names(self):
+        names = self.meta.get(NAME, 'DoesNotExist')
+        if type(names) is not types.ListType:
+            names = [names]
+        return names
+
+    @property
     def name(self):
-        name = self.meta.get(NAME, 'DoesNotExist')
-        if type(name) is types.ListType:
-            name = name[0]
-        return name
+        return self._name or self.names[0]
+
+    def set_context(self, context):
+        for name in self.names:
+            if name.startswith(context):
+                self._name = name
+                return
 
     def _load(self):
-        name = self._doc[NAME]
-        if type(name) is types.ListType:
-            name = name[0]
-        meta, data = self.backend.retrieve(name, self.revid) # raises KeyError if rev does not exist
+        meta, data = self.backend.retrieve(self.name, self.revid) # raises KeyError if rev does not exist
         self.meta = Meta(self, self._doc, meta)
         self._data = data
         return meta, data
--- a/MoinMoin/storage/middleware/protecting.py	Tue Nov 01 12:21:54 2011 -0200
+++ b/MoinMoin/storage/middleware/protecting.py	Tue Nov 01 12:24:16 2011 -0200
@@ -272,6 +272,9 @@
         self.require(READ)
         return self.rev.data
 
+    def set_context(self, context):
+        self.rev.set_context(context)
+
     def close(self):
         self.rev.close()