changeset 127:4408881ee6e3

indexing backend mixin: intercept create_item() to add NAME/UUID if it is not there
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 14 Mar 2011 18:49:12 +0100
parents 81f0ff7a5cae
children b0cd58f89c3f eebbee623c44
files MoinMoin/storage/backends/indexing.py
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/storage/backends/indexing.py	Mon Mar 14 04:18:36 2011 +0100
+++ b/MoinMoin/storage/backends/indexing.py	Mon Mar 14 18:49:12 2011 +0100
@@ -22,6 +22,9 @@
 import os
 import time, datetime
 
+from uuid import uuid4
+make_uuid = lambda: unicode(uuid4().hex)
+
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
@@ -39,6 +42,19 @@
         super(IndexingBackendMixin, self).__init__(*args, **kw)
         self._index = ItemIndex(index_uri)
 
+    def create_item(self, itemname):
+        """
+        intercept new item creation and make sure there is NAME / UUID in the item
+        """
+        item = super(IndexingBackendMixin, self).create_item(itemname)
+        item.change_metadata()
+        if NAME not in item:
+            item[NAME] = itemname
+        if UUID not in item:
+            item[UUID] = make_uuid()
+        item.publish_metadata()
+        return item
+
     def index_rebuild(self):
         return self._index.index_rebuild(self)
 
@@ -181,8 +197,6 @@
     # TODO maybe use this class later for data indexing also,
     # TODO by intercepting write() to index data written to a revision
 
-from uuid import uuid4 as gen_uuid
-
 from MoinMoin.util.kvstore import KVStoreMeta, KVStore
 
 from sqlalchemy import Table, Column, Integer, String, Unicode, DateTime, PickleType, MetaData, ForeignKey