]> git.openstreetmap.org Git - osqa.git/commitdiff
Some changes necessary to make cache work on Django 1.2.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 19 May 2010 23:29:52 +0000 (23:29 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 19 May 2010 23:29:52 +0000 (23:29 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@307 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/action.py
forum/models/base.py
forum/models/meta.py

index 785ed2da965a5461e794f97fcade2cc476068b65..82ca34a8c6e2d65d8e1dc1310c9b084bac08d919 100644 (file)
@@ -4,29 +4,28 @@ from threading import Thread
 from base import *\r
 import re\r
 \r
+class ActionQuerySet(models.query.QuerySet):\r
+    def get(self, *args, **kwargs):\r
+        action = super(ActionQuerySet, self).get(*args, **kwargs)\r
+        if self.model == Action:\r
+            return action.leaf()\r
+        return action\r
+\r
 class ActionManager(models.Manager):\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).filter(canceled=False)\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
     user = models.ForeignKey('User', related_name="actions")\r
     ip   = models.CharField(max_length=16)\r
index 627888f47f080db4c1a186e35fddf11ee3cd8312..276c8f6f06f4140c1373f7802052fe655b57d280 100644 (file)
@@ -40,6 +40,27 @@ class CachedQuerySet(models.query.QuerySet):
         else:
             return self
 
+    def get(self, *args, **kwargs):
+        try:
+            pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact'
+                            ) or k.endswith('_ptr__pk') or k.endswith('_ptr__id')][0]
+        except:
+            pk = None
+
+        if pk is not None:
+            key = self.model.cache_key(pk)
+            obj = cache.get(key)
+
+            if obj is None:
+                obj = super(CachedQuerySet, self).get(*args, **kwargs)
+                obj.__class__.objects.cache_obj(obj)
+            else:
+                d = obj.__dict__
+
+            return obj
+
+        return super(CachedQuerySet, self).get(*args, **kwargs) 
+
 from action import Action
 
 class CachedManager(models.Manager):
@@ -58,27 +79,6 @@ class CachedManager(models.Manager):
 
         cache.set(self.model.cache_key(obj.id), obj, 60 * 60)
 
-    def get(self, *args, **kwargs):
-        try:
-            pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact'
-                            ) or k.endswith('_ptr__pk') or k.endswith('_ptr__id')][0]
-        except:
-            pk = None
-
-        if pk is not None:
-            key = self.model.cache_key(pk)
-            obj = cache.get(key)
-
-            if obj is None:
-                obj = super(CachedManager, self).get(*args, **kwargs)
-                self.cache_obj(obj)
-            else:
-                d = obj.__dict__
-
-            return obj
-        
-        return super(CachedManager, self).get(*args, **kwargs)
-
     def get_or_create(self, *args, **kwargs):
         try:
             return self.get(*args, **kwargs)
index 3fd068081e3ef1d7cc65b2744d22dc9f38a52b88..fca763fd5d78a0db59a22900c6d0cc2d0490092a 100644 (file)
@@ -24,21 +24,26 @@ class Flag(models.Model):
         app_label = 'forum'\r
         unique_together = ('user', 'node')\r
 \r
-class BadgeManager(models.Manager):\r
-    use_for_related_fields = True\r
-    \r
+class BadgesQuerySet(models.query.QuerySet):\r
     def get(self, *args, **kwargs):\r
         try:\r
             pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact')][0]\r
         except:\r
-            return super(BadgeManager, self).get(*args, **kwargs)\r
+            return super(BadgesQuerySet, self).get(*args, **kwargs)\r
 \r
         from forum.badges.base import BadgesMeta\r
         badge = BadgesMeta.by_id.get(int(pk), None)\r
         if not badge:\r
-            return super(BadgeManager, self).get(*args, **kwargs)\r
+            return super(BadgesQuerySet, self).get(*args, **kwargs)\r
         return badge.ondb\r
 \r
+\r
+class BadgeManager(models.Manager):\r
+    use_for_related_fields = True\r
+\r
+    def get_query_set(self):\r
+        return BadgesQuerySet(self.model)\r
+\r
 class Badge(models.Model):\r
     GOLD = 1\r
     SILVER = 2\r