Split the dirty management out from sessiondata.
authorFredrik Tolf <fredrik@dolda2000.com>
Tue, 27 Dec 2011 23:56:06 +0000 (00:56 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 28 Dec 2011 00:04:16 +0000 (01:04 +0100)
wrw/util.py

index 3da6053..a0e4095 100644 (file)
@@ -29,7 +29,6 @@ class sessiondata(object):
                 return sess[cls]
             except KeyError:
                 ret = cls(req)
-                ret._is_dirty = [False]
                 sess[cls] = ret
                 return ret
 
@@ -37,17 +36,25 @@ class sessiondata(object):
     def sessdb(cls):
         return session.default
 
+class autodirty(sessiondata):
+    @classmethod
+    def get(cls, req):
+        ret = super(autodirty, cls).get(req)
+        if "_is_dirty" not in ret.__dict__:
+            ret.__dict__["_is_dirty"] = False
+
     def sessfrozen(self):
-        self._is_dirty[:] = [False]
+        self.__dict__["_is_dirty"] = False
 
     def sessdirty(self):
-        return self._is_dirty[0]
+        return self._is_dirty
 
     def __setattr__(self, name, value):
-        if hasattr(self, "_is_dirty"):
-            self._is_dirty[:] = [True]
-        super(sessiondata, self).__setattr__(name, value)
+        super(autodirty, self).__setattr__(name, value)
+        if "_is_dirty" in self.__dict__:
+            self.__dict__["_is_dirty"] = True
 
     def __delattr__(self, name):
-        super(sessiondata, self).__delattr__(name)
-        self._is_dirty[:] = [True]
+        super(autodirty, self).__delattr__(name, value)
+        if "_is_dirty" in self.__dict__:
+            self.__dict__["_is_dirty"] = True