summaryrefslogtreecommitdiffstats
path: root/askbot/models/badges.py
diff options
context:
space:
mode:
Diffstat (limited to 'askbot/models/badges.py')
-rw-r--r--askbot/models/badges.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/askbot/models/badges.py b/askbot/models/badges.py
index 5e56b499..61149df3 100644
--- a/askbot/models/badges.py
+++ b/askbot/models/badges.py
@@ -24,8 +24,8 @@ from django.utils.translation import ugettext as _
from django.dispatch import Signal
from askbot.models.repute import BadgeData, Award
from askbot.models.user import Activity
-from askbot.models.meta import Comment
from askbot.models.question import FavoriteQuestion as Fave#name collision
+from askbot.models.post import Post
from askbot import const
from askbot.conf import settings as askbot_settings
from askbot.utils.decorators import auto_now_timestamp
@@ -265,7 +265,7 @@ class SelfLearner(Badge):
return False
min_upvotes = askbot_settings.SELF_LEARNER_BADGE_MIN_UPVOTES
- question = context_object.question
+ question = context_object.thread._question_post()
answer = context_object
if question.author == answer.author and answer.score >= min_upvotes:
@@ -404,7 +404,7 @@ class FrequentedQuestion(Badge):
context_object = None, timestamp = None):
if context_object.post_type != 'question':
return False
- if context_object.view_count >= self.min_views:
+ if context_object.thread.view_count >= self.min_views:
return self.award(context_object.author, context_object, timestamp)
return False
@@ -461,7 +461,7 @@ class Scholar(Badge):
if context_object.post_type != 'answer':
return False
answer = context_object
- if answer.question.author != actor:
+ if answer.thread._question_post().author != actor:
return False
return self.award(actor, context_object, timestamp)
@@ -485,7 +485,7 @@ class VotedAcceptedAnswer(Badge):
if context_object.post_type != 'answer':
return None
answer = context_object
- if answer.score >= self.min_votes and answer.accepted:
+ if answer.score >= self.min_votes and answer.accepted():
return self.award(answer.author, answer, timestamp)
class Enlightened(VotedAcceptedAnswer):
@@ -533,7 +533,7 @@ class Necromancer(Badge):
if context_object.post_type != 'answer':
return False
answer = context_object
- question = answer.question
+ question = answer.thread._question_post()
delta = datetime.timedelta(askbot_settings.NECROMANCER_BADGE_MIN_DELAY)
min_score = askbot_settings.NECROMANCER_BADGE_MIN_UPVOTES
if answer.added_at - question.added_at >= delta \
@@ -674,7 +674,7 @@ class FavoriteTypeBadge(Badge):
question = context_object
#model FavoriteQuestion imported under alias of Fave
count = Fave.objects.filter(
- question = question
+ thread = question.thread
).exclude(
user = question.author
).count()
@@ -739,7 +739,7 @@ class Commentator(Badge):
def consider_award(self, actor = None,
context_object = None, timestamp = None):
- num_comments = Comment.objects.filter(user = actor).count()
+ num_comments = Post.objects.get_comments().filter(author=actor).count()
if num_comments >= askbot_settings.COMMENTATOR_BADGE_MIN_COMMENTS:
return self.award(actor, context_object, timestamp)
return False
@@ -762,9 +762,7 @@ class Taxonomist(Badge):
tag = context_object
taxonomist_threshold = askbot_settings.TAXONOMIST_BADGE_MIN_USE_COUNT
- #the "-1" is used because tag counts are updated in a bulk query
- #that does not update the value in the python object
- if tag.used_count == taxonomist_threshold - 1:
+ if tag.used_count == taxonomist_threshold:
return self.award(tag.created_by, tag, timestamp)
return False
@@ -880,6 +878,11 @@ def init_badges():
#from the __init__ function?
for key in BADGES.keys():
get_badge(key).get_stored_data()
+ #remove any badges from the database
+ #that are no longer in the BADGES dictionary
+ BadgeData.objects.exclude(
+ slug__in = map(slugify, BADGES.keys())
+ ).delete()
award_badges_signal = Signal(
providing_args=[