]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/action.py
Fixes OSQA 275, Password changing is not reliable.
[osqa.git] / forum / models / action.py
index 90c61f8c548f153b839744de3a19a2f49c9776db..7f9a7c189acf73817d9f64d72969b919ace2e072 100644 (file)
@@ -4,30 +4,36 @@ from threading import Thread
 from base import *\r
 import re\r
 \r
-class ActionManager(models.Manager):\r
+class ActionQuerySet(CachedQuerySet):\r
+    def obj_from_datadict(self, datadict):\r
+        cls = ActionProxyMetaClass.types.get(datadict['action_type'], None)\r
+        if cls:\r
+            obj = cls()\r
+            obj.__dict__.update(datadict)\r
+            return obj\r
+        else:\r
+            return super(ActionQuerySet, self).obj_from_datadict(datadict)\r
+\r
+    def get(self, *args, **kwargs):\r
+        return super(ActionQuerySet, self).get(*args, **kwargs).leaf()\r
+\r
+class ActionManager(CachedManager):\r
     use_for_related_fields = True\r
 \r
     def get_query_set(self):\r
-        qs = super(ActionManager, self).get_query_set().filter(canceled=False)\r
+        qs = ActionQuerySet(self.model)\r
 \r
         if self.model is not Action:\r
             return qs.filter(action_type=self.model.get_type())\r
         else:\r
             return qs\r
 \r
-    def get(self, *args, **kwargs):\r
-        action = super(ActionManager, self).get(*args, **kwargs)\r
-        if self.model == Action:\r
-            return action.leaf()\r
-        return action\r
-\r
     def get_for_types(self, types, *args, **kwargs):\r
         kwargs['action_type__in'] = [t.get_type() for t in types]\r
         return self.get(*args, **kwargs)\r
 \r
-        \r
 \r
-class Action(models.Model):\r
+class Action(BaseModel):\r
     user = models.ForeignKey('User', related_name="actions")\r
     ip   = models.CharField(max_length=16)\r
     node = models.ForeignKey('Node', null=True, related_name="actions")\r
@@ -70,7 +76,7 @@ class Action(models.Model):
         return ""\r
 \r
     def describe(self, viewer=None):\r
-        return ""\r
+        return self.__class__.__name__\r
 \r
     def get_absolute_url(self):\r
         if self.node:\r
@@ -95,7 +101,9 @@ class Action(models.Model):
             return self\r
 \r
         leaf = leaf_cls()\r
-        leaf.__dict__ = self.__dict__\r
+        d = self._as_dict()\r
+        leaf.__dict__.update(self._as_dict())\r
+        l = leaf._as_dict()\r
         return leaf\r
 \r
     @classmethod\r
@@ -115,16 +123,16 @@ class Action(models.Model):
         super(Action, self).save(*args, **kwargs)\r
 \r
         if isnew:\r
-            if (self.node is None) or (not self.node.wiki):\r
+            if (self.node is None) or (not self.node.nis.wiki):\r
                 self.repute_users()\r
             self.process_action()\r
             self.trigger_hooks(True)\r
 \r
         return self\r
 \r
-    def delete(self):\r
+    def delete(self, *args, **kwargs):\r
         self.cancel_action()\r
-        super(Action, self).delete()\r
+        super(Action, self).delete(*args, **kwargs)\r
 \r
     def cancel(self, user=None, ip=None):\r
         if not self.canceled:\r
@@ -175,7 +183,7 @@ def trigger_hooks_threaded(action, hooks, new):
                 except Exception, e:\r
                     logging.error("Error in %s hook: %s" % (cls.__name__, str(e)))\r
 \r
-class ActionProxyMetaClass(models.Model.__metaclass__):\r
+class ActionProxyMetaClass(BaseMetaClass):\r
     types = {}\r
 \r
     def __new__(cls, *args, **kwargs):\r
@@ -230,6 +238,9 @@ class DummyActionProxy(object):
 \r
     hooks = []\r
 \r
+    def __init__(self, ip=None):\r
+        self.ip = ip\r
+\r
     def process_data(self, **data):\r
         pass\r
 \r
@@ -274,11 +285,11 @@ class ActionRepute(models.Model):
 \r
     def save(self, *args, **kwargs):\r
         super(ActionRepute, self).save(*args, **kwargs)\r
-        self.user.reputation = models.F('reputation') + self.value\r
+        self.user.reputation += self.value\r
         self.user.save()\r
 \r
     def delete(self):\r
-        self.user.reputation = models.F('reputation') - self.value\r
+        self.user.reputation -= self.value\r
         self.user.save()\r
         super(ActionRepute, self).delete()\r
 \r