]> git.openstreetmap.org Git - osqa.git/blobdiff - forum_modules/default_badges/badges.py
add a new after_head_js block (immediately after the <head> tag), allows to add track...
[osqa.git] / forum_modules / default_badges / badges.py
index ba01a0fe39e7ffed3fb7f9b6193a1c777e10c39f..f9da788d6c5ad434a22f7d7475b90f4ac9e2d014 100644 (file)
@@ -16,8 +16,8 @@ class QuestionViewBadge(AbstractBadge):
         return _('Asked a question with %s views') % str(self.nviews)
 
     def award_to(self, action):
         return _('Asked a question with %s views') % str(self.nviews)
 
     def award_to(self, action):
-        if action.question.extra_count == int(self.nviews):
-            return action.question.author
+        if action.node.extra_count == int(self.nviews):
+            return action.node.author
 
 
 class PopularQuestion(QuestionViewBadge):
 
 
 class PopularQuestion(QuestionViewBadge):
@@ -36,25 +36,23 @@ class FamousQuestion(QuestionViewBadge):
     nviews = settings.FAMOUS_QUESTION_VIEWS
 
 
     nviews = settings.FAMOUS_QUESTION_VIEWS
 
 
-
-
 class NodeScoreBadge(AbstractBadge):
     abstract = True
     listen_to = (VoteAction,)
 
 class NodeScoreBadge(AbstractBadge):
     abstract = True
     listen_to = (VoteAction,)
 
-    @property
-    def description(self):
-        return _('Answer voted up %s times') % str(self.expected_score)
-
     def award_to(self, action):
         if (action.node.node_type == self.node_type) and (action.node.score == int(self.expected_score)):
             return action.node.author
     def award_to(self, action):
         if (action.node.node_type == self.node_type) and (action.node.score == int(self.expected_score)):
             return action.node.author
-            
+
 
 class QuestionScoreBadge(NodeScoreBadge):
     abstract = True
     node_type = "question"
 
 
 class QuestionScoreBadge(NodeScoreBadge):
     abstract = True
     node_type = "question"
 
+    @property
+    def description(self):
+        return _('Question voted up %s times') % str(self.expected_score)
+
 class NiceQuestion(QuestionScoreBadge):
     expected_score = settings.NICE_QUESTION_VOTES_UP
     name = _("Nice Question")
 class NiceQuestion(QuestionScoreBadge):
     expected_score = settings.NICE_QUESTION_VOTES_UP
     name = _("Nice Question")
@@ -74,6 +72,10 @@ class AnswerScoreBadge(NodeScoreBadge):
     abstract = True
     node_type = "answer"
 
     abstract = True
     node_type = "answer"
 
+    @property
+    def description(self):
+        return _('Answer voted up %s times') % str(self.expected_score)
+
 class NiceAnswer(AnswerScoreBadge):
     expected_score = settings.NICE_ANSWER_VOTES_UP
     name = _("Nice Answer")
 class NiceAnswer(AnswerScoreBadge):
     expected_score = settings.NICE_ANSWER_VOTES_UP
     name = _("Nice Answer")
@@ -89,7 +91,6 @@ class GreatAnswer(AnswerScoreBadge):
     name = _("Great Answer")
 
 
     name = _("Great Answer")
 
 
-
 class FavoriteQuestionBadge(AbstractBadge):
     abstract = True
     listen_to = (FavoriteAction,)
 class FavoriteQuestionBadge(AbstractBadge):
     abstract = True
     listen_to = (FavoriteAction,)
@@ -108,11 +109,11 @@ class FavoriteQuestion(FavoriteQuestionBadge):
     expected_count = settings.FAVORITE_QUESTION_FAVS
 
 class StellarQuestion(FavoriteQuestionBadge):
     expected_count = settings.FAVORITE_QUESTION_FAVS
 
 class StellarQuestion(FavoriteQuestionBadge):
+    type = Badge.GOLD
     name = _("Stellar Question")
     expected_count = settings.STELLAR_QUESTION_FAVS
 
 
     name = _("Stellar Question")
     expected_count = settings.STELLAR_QUESTION_FAVS
 
 
-
 class Disciplined(AbstractBadge):
     listen_to = (DeleteAction,)
     name = _("Disciplined")
 class Disciplined(AbstractBadge):
     listen_to = (DeleteAction,)
     name = _("Disciplined")
@@ -157,7 +158,7 @@ class Supporter(AbstractBadge):
 class FirstActionBadge(AbstractBadge):
     award_once = True
     abstract = True
 class FirstActionBadge(AbstractBadge):
     award_once = True
     abstract = True
-    
+
     def award_to(self, action):
         if (self.listen_to[0].objects.filter(user=action.user).count() == 1):
             return action.user
     def award_to(self, action):
         if (self.listen_to[0].objects.filter(user=action.user).count() == 1):
             return action.user
@@ -201,7 +202,6 @@ class Autobiographer(AbstractBadge):
             return user
 
 
             return user
 
 
-
 class CivicDuty(AbstractBadge):
     type = Badge.SILVER
     award_once = True
 class CivicDuty(AbstractBadge):
     type = Badge.SILVER
     award_once = True
@@ -221,7 +221,8 @@ class Pundit(AbstractBadge):
     description = _('Left %s comments') % settings.PUNDIT_COMMENT_COUNT
 
     def award_to(self, action):
     description = _('Left %s comments') % settings.PUNDIT_COMMENT_COUNT
 
     def award_to(self, action):
-        if (action.user.nodes.filter(node_type="comment", deleted=None)) == int(settings.CIVIC_DUTY_VOTES):
+        if action.user.nodes.filter_state(deleted=False).filter(node_type="comment").count() == int(
+                settings.PUNDIT_COMMENT_COUNT):
             return action.user
 
 
             return action.user
 
 
@@ -232,11 +233,12 @@ class SelfLearner(AbstractBadge):
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (action.node.author == action.node.parent.author) and (
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (action.node.author == action.node.parent.author) and (
-            action.node.score == int(settings.SELF_LEARNER_UP_VOTES)):
+        action.node.score == int(settings.SELF_LEARNER_UP_VOTES)):
             return action.node.author
 
 
 class StrunkAndWhite(AbstractBadge):
             return action.node.author
 
 
 class StrunkAndWhite(AbstractBadge):
+    type = Badge.SILVER
     award_once = True
     listen_to = (ReviseAction,)
     name = _("Strunk & White")
     award_once = True
     listen_to = (ReviseAction,)
     name = _("Strunk & White")
@@ -254,7 +256,8 @@ class Student(AbstractBadge):
     description = _('Asked first question with at least one up vote')
 
     def award_to(self, action):
     description = _('Asked first question with at least one up vote')
 
     def award_to(self, action):
-        if (action.node.node_type == "question") and (action.node.author.nodes.filter(node_type="question", deleted=None, score=1).count() == 1):
+        if (action.node.node_type == "question") and (action.node.author.nodes.filter_state(deleted=False).filter(
+                node_type="question", score=1).count() == 1):
             return action.node.author
 
 
             return action.node.author
 
 
@@ -265,7 +268,8 @@ class Teacher(AbstractBadge):
     description = _('Answered first question with at least one up vote')
 
     def award_to(self, action):
     description = _('Answered first question with at least one up vote')
 
     def award_to(self, action):
-        if (action.node.node_type == "answer") and (action.node.author.nodes.filter(node_type="answer", deleted=None, score=1).count() == 1):
+        if (action.node.node_type == "answer") and (action.node.author.nodes.filter_state(deleted=False).filter(
+                node_type="answer", score=1).count() == 1):
             return action.node.author
 
 
             return action.node.author
 
 
@@ -278,7 +282,7 @@ class Enlightened(AbstractBadge):
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (action.node.accepted) and (
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (action.node.accepted) and (
-            action.node.score >= int(settings.ENLIGHTENED_UP_VOTES)):
+        action.node.score >= int(settings.ENLIGHTENED_UP_VOTES)):
             return action.node.author
 
 
             return action.node.author
 
 
@@ -290,7 +294,7 @@ class Guru(AbstractBadge):
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (action.node.accepted) and (
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (action.node.accepted) and (
-            action.node.score >= int(settings.ENLIGHTENED_UP_VOTES)):
+        action.node.score >= int(settings.GURU_UP_VOTES)):
             return action.node.author
 
 
             return action.node.author
 
 
@@ -303,7 +307,8 @@ class Necromancer(AbstractBadge):
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (
 
     def award_to(self, action):
         if (action.node.node_type == "answer") and (
-            action.node.added_at >= (action.node.question.added_at + timedelta(days=int(settings.NECROMANCER_DIF_DAYS)))):
+        action.node.added_at >= (action.node.question.added_at + timedelta(days=int(settings.NECROMANCER_DIF_DAYS)))
+        ) and (int(action.node.score) == int(settings.NECROMANCER_UP_VOTES)):
             return action.node.author
 
 class Taxonomist(AbstractBadge):
             return action.node.author
 
 class Taxonomist(AbstractBadge):
@@ -315,3 +320,11 @@ class Taxonomist(AbstractBadge):
     def award_to(self, action):
         return None
 
     def award_to(self, action):
         return None
 
+class ValidatedEmail(AbstractBadge):
+    type = Badge.BRONZE
+    listen_to = (EmailValidationAction,)
+    name = _("Validated Email")
+    description = _("User who has validated email associated to the account")
+
+    def award_to(self, action):
+        return action.user
\ No newline at end of file