Code

more batching cleanup
[roundup.git] / roundup / backends / back_metakit.py
index 26bf2aa33a4b4d8b8c8f50d92cdbc32ebd44ab32..89193822f499a5be15aacfbdd4082f98087052f7 100755 (executable)
@@ -12,6 +12,12 @@ def Database(config, journaltag=None):
     if db is None or db._db is None:
         db = _Database(config, journaltag)
         _dbs[config.DATABASE] = db
+    else:
+        db.journaltag = journaltag
+        try:
+            delattr(db, 'curuserid')
+        except AttributeError:
+            pass
     return db
 
 class _Database(hyperdb.Database):
@@ -273,7 +279,7 @@ class Class:
         if not isnew:
             self.fireAuditors('set', nodeid, propvalues)
         if not propvalues:
-            return
+            return propvalues
         if propvalues.has_key('id'):
             raise KeyError, '"id" is reserved'
         if self.db.journaltag is None:
@@ -328,6 +334,9 @@ class Class:
                 if value is not None and not isinstance(value, type('')):
                     raise ValueError, 'property "%s" link value be a string'%(
                         propname)
+                # Roundup sets to "unselected" by passing None
+                if value is None:
+                    value = 0   
                 # if it isn't a number, it's a key
                 try:
                     int(value)
@@ -408,6 +417,8 @@ class Class:
                 for id in adds:
                     sv.append(fid=int(id))
                 changes[key] = oldvalue
+                if not rmvd and not adds:
+                    del propvalues[key]
                     
 
             elif isinstance(prop, hyperdb.String):
@@ -456,7 +467,7 @@ class Class:
 
         # nothing to do?
         if not propvalues:
-            return
+            return propvalues
         if not propvalues.has_key('activity'):
             row.activity = int(time.time())
         if isnew:
@@ -474,6 +485,8 @@ class Class:
                 self.db.addjournal(self.classname, nodeid, _SET, changes)
                 self.fireReactors('set', nodeid, oldnode)
 
+        return propvalues
+    
     def retire(self, nodeid):
         self.fireAuditors('retire', nodeid, None)
         view = self.getview(1)
@@ -625,7 +638,9 @@ class Class:
         # search_matches is None or a set (dict of {nodeid: {propname:[nodeid,...]}})
         # filterspec is a dict {propname:value}
         # sort and group are lists of propnames
-        
+        # sort and group are (dir, prop) where dir is '+', '-' or None
+        #                    and prop is a prop name or None
+
         where = {'_isdel':0}
         mlcriteria = {}
         regexes = {}
@@ -732,10 +747,10 @@ class Class:
         if sort or group:
             sortspec = []
             rev = []
-            for propname in group + sort:
+            for dir, propname in group, sort:
+                if propname is None: continue
                 isreversed = 0
-                if propname[0] == '-':
-                    propname = propname[1:]
+                if dir == '-':
                     isreversed = 1
                 try:
                     prop = getattr(v, propname)
@@ -1000,7 +1015,9 @@ class IssueClass(Class, roundupdb.IssueClass):
         if not properties.has_key('files'):
             properties['files'] = hyperdb.Multilink("file")
         if not properties.has_key('nosy'):
-            properties['nosy'] = hyperdb.Multilink("user")
+            # note: journalling is turned off as it really just wastes
+            # space. this behaviour may be overridden in an instance
+            properties['nosy'] = hyperdb.Multilink("user", do_journal="no")
         if not properties.has_key('superseder'):
             properties['superseder'] = hyperdb.Multilink(classname)
         Class.__init__(self, db, classname, **properties)