]> git.openstreetmap.org Git - osqa.git/commitdiff
Fixes a problem that might allow some users to get multiple badges in some strange...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 22 Jun 2010 11:23:59 +0000 (11:23 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 22 Jun 2010 11:23:59 +0000 (11:23 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@439 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/actions/user.py
forum/badges/base.py

index a3856a83bbd53d2dd5fbc011d56490b6678067d1..e8f1035d3a2d0946651ecb37fb40caf2454f5d34 100644 (file)
@@ -1,5 +1,6 @@
 from django.utils.translation import ugettext as _
 from django.db.models import F
+from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
 from forum.models.action import ActionProxy
 from forum.models import Award, Badge, ValidationHash
 from forum import settings
@@ -94,7 +95,7 @@ class AwardAction(ActionProxy):
                 return Award.objects.get(user=user, badge=badge).action
             else:
                 return Award.objects.get(user=user, node=node, badge=badge).action
-        except:
+        except ObjectDoesNotExist:
             return None
 
     def describe(self, viewer=None):
index 3af46f7c20496c0ac101e9af9658343f0528f571..1900119284224270ab6d954d7e6a680e6fd1b4dc 100644 (file)
@@ -1,7 +1,7 @@
 import re
 from string import lower
 
-from django.contrib.contenttypes.models import ContentType
+from django.core.exceptions import MultipleObjectsReturned
 from django.db.models.signals import post_save
 
 from forum.models import Badge, Node, Action
@@ -58,14 +58,20 @@ class AbstractBadge(object):
 
     @classmethod
     def award(cls, user, action, once=False):
-        if once:
-            node = None
-            awarded = AwardAction.get_for(user, cls.ondb)
-        else:
-            node = action.node
-            awarded = AwardAction.get_for(user, cls.ondb, node)
+        try:
+            if once:
+                node = None
+                awarded = AwardAction.get_for(user, cls.ondb)
+            else:
+                node = action.node
+                awarded = AwardAction.get_for(user, cls.ondb, node)
 
-        trigger = isinstance(action, Action) and action or None
+            trigger = isinstance(action, Action) and action or None
 
-        if not awarded:
-            AwardAction(user=user, node=node, ip=action.ip).save(data=dict(badge=cls.ondb, trigger=trigger))
\ No newline at end of file
+            if not awarded:
+                AwardAction(user=user, node=node, ip=action.ip).save(data=dict(badge=cls.ondb, trigger=trigger))
+        except MultipleObjectsReturned:
+            if node:
+                logging.error('Found multiple %s badges awarded for user %s (%s)' % (self.name, user.username, user.id))
+            else:
+                logging.error('Found multiple %s badges awarded for user %s (%s) and node %s' % (self.name, user.username, user.id, node.id))
\ No newline at end of file