1. hacklab
  2. moin-2.0

Commits

hacklab  committed 97f917f

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

  • Participants
  • Parent commits 900263d
  • Branches namespaces

Comments (0)

Files changed (3)

File MoinMoin/items/__init__.py

View file
  • Ignore whitespace
             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 = []

File MoinMoin/storage/middleware/indexing.py

View file
  • Ignore whitespace
     """
     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:
         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

File MoinMoin/storage/middleware/protecting.py

View file
  • Ignore whitespace
         self.require(READ)
         return self.rev.data
 
+    def set_context(self, context):
+        self.rev.set_context(context)
+
     def close(self):
         self.rev.close()