]> git.openstreetmap.org Git - osqa.git/commitdiff
several improvements in the caching system
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 19 Apr 2010 12:08:36 +0000 (12:08 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 19 Apr 2010 12:08:36 +0000 (12:08 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@55 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/base.py
forum/models/meta.py
forum/views/admin.py
forum/views/commands.py
forum/views/readers.py

index 78f12428b45c16d15fbe7e854f03fff534eb8675..08ccb44dbbb1fe424de70de5b1f70851f8bc7bf8 100644 (file)
@@ -24,7 +24,8 @@ class CachedManager(models.Manager):
 
     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')][0]
+            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
 
index c01c018f77daa5c4cef9cdd6e7decab5cf39a36d..86a479cde1999b820b029a1184fa03a85066809c 100644 (file)
@@ -20,7 +20,7 @@ class Vote(MetaContent, CancelableContent, UserContent):
         return '[%s] voted at %s: %s' %(self.user, self.voted_at, self.vote)
 
     def _update_post_vote_count(self, diff):
-        post = self.node
+        post = self.node.leaf
         field = self.vote == 1 and 'vote_up_count' or 'vote_down_count'
         post.__dict__[field] = post.__dict__[field] + diff
         post.save()
index 3fa02bcfb0f82aef36f714aa7067d03fc30910e1..7a299221f7f1f6e276b7653eac92ec65539b7b3e 100644 (file)
@@ -159,6 +159,7 @@ def go_defaults(request):
 @super_user_required
 def recalculate_denormalized(request):
     for n in Node.objects.all():
+        n = n.leaf
         n.vote_up_count = n.votes.filter(canceled=False, vote=1).count()
         n.vote_down_count = n.votes.filter(canceled=False, vote=-1).count()
         n.save()
index 4ff80f8c50529acf38462a9b8fee67a90ed6bd06..b12991137d7c9f65d8e6fc1aed1af3778a601433 100644 (file)
@@ -63,7 +63,7 @@ class CannotDoubleActionException(Exception):
 
 @command
 def vote_post(request, id, vote_type):
-    post = get_object_or_404(Node, id=id)
+    post = get_object_or_404(Node, id=id).leaf
     vote_score = vote_type == 'up' and 1 or -1
     user = request.user
 
index 879dbcf8083ca51207f04f09f14e98c9d3b3aff9..ac20dae11667821bd8b542d11b1cace4a2612beb 100644 (file)
@@ -210,7 +210,7 @@ def match_question_slug(slug):
 
 def question(request, id, slug):
     try:
-        question = Question.objects.get(id=id)
+        question = Question.objects.get(node_type="question", id=id)
     except:
         question = match_question_slug(slug)
         if question is not None: