]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/project_badges/badges.py
Add README to the source code
[osqa.git] / forum_modules / project_badges / badges.py
index f0cc4e25018645b4be7b1bb0c528243cf6f583aa..9633567c487feb47052865fda8b3b9936bc5482a 100644 (file)
@@ -1,21 +1,20 @@
-from forum.badges.base import CountableAbstractBadge
-from forum.models import Question, Tag
-from forum import const
 from django.utils.translation import ugettext as _
+from forum.badges.base import AbstractBadge
+from forum.models import Badge, Tag
+from forum.actions import VoteUpAction
 import settings
 
-class BugBusterBadge(CountableAbstractBadge):
-    type = const.SILVER_BADGE
-    description = _('Got %s upvotes in a question tagged with "bug"') % str(settings.BUG_BUSTER_VOTES_UP)
+class BugBuster(AbstractBadge):
+    type = Badge.SILVER
+    name = _("Bug Buster")
+    description = _('Got %s upvotes in a question tagged with "bug"') % settings.BUG_BUSTER_VOTES_UP
+    listen_to = (VoteUpAction, )
 
-    def __init__(self):
-
-        def handler(instance):
+    def award_to(self, action):
+        if action.node.node_type == "question" and int(action.node.score) == int(settings.BUG_BUSTER_VOTES_UP):
             try:
-                bug_tag = Tag.objects.get(name='bug')
-                if bug_tag in instance.tags.all():
-                    self.award_badge(instance.author, instance)
-            except:
+                bug = Tag.objects.get(name="bug")
+                if bug in action.node.tags.all():
+                    return action.node.author
+            except Exception:
                 pass
-
-        super(BugBusterBadge, self).__init__(Question, 'vote_up_count', settings.BUG_BUSTER_VOTES_UP, handler)
\ No newline at end of file