- if once:
- node = None
- awarded = AwardAction.get_for(user, cls.ondb)
- else:
- node = action.node
- awarded = AwardAction.get_for(user, cls.ondb, node)
-
- if not awarded:
- AwardAction(user=user, node=node, ip=action.ip).save(data=dict(badge=cls.ondb, trigger=action))
\ No newline at end of file
+ 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
+
+ if not awarded:
+ AwardAction(user=user, node=node).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