]> git.openstreetmap.org Git - osqa.git/blob - forum_modules/project_badges/badges.py
adapted badges to the new schema
[osqa.git] / forum_modules / project_badges / badges.py
1 from forum.badges.base import CountableAbstractBadge
2 from forum.models import Question, Tag
3 from forum import const
4 from django.utils.translation import ugettext as _
5 import settings
6
7 class BugBusterBadge(CountableAbstractBadge):
8     type = const.SILVER_BADGE
9     description = _('Got %s upvotes in a question tagged with "bug"') % str(settings.BUG_BUSTER_VOTES_UP)
10
11     def __init__(self):
12
13         def handler(instance):
14             try:
15                 bug_tag = Tag.objects.get(name='bug')
16                 if bug_tag in instance.tags.all():
17                     self.award_badge(instance.author, instance)
18             except:
19                 pass
20
21         super(BugBusterBadge, self).__init__(Question, 'vote_up_count', settings.BUG_BUSTER_VOTES_UP, handler)