]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/badges/base.py
adapted badges to the new schema
[osqa.git] / forum / badges / base.py
index c3e9fcb85cd491f5c80b7f3698ca160da7628e30..c2dbe30763c72d0a7f9fe9ccaf30a30caa688bec 100644 (file)
@@ -5,7 +5,7 @@ from django.contrib.contenttypes.models import ContentType
 from django.db.models.signals import post_save
 
 from forum.models.user import activity_record
-from forum.models import Badge, Award, Activity
+from forum.models import Badge, Award, Activity, Node
 
 import logging
 
@@ -74,6 +74,14 @@ class PostCountableAbstractBadge(CountableAbstractBadge):
 
         super(PostCountableAbstractBadge, self).__init__(model, field, expected_value, handler)
 
+class NodeCountableAbstractBadge(CountableAbstractBadge):
+    def __init__(self, node_type, field, expected_value):
+
+        def handler(instance):
+            if instance.node_type == node_type:
+                self.award_badge(instance.author, instance)
+
+        super(NodeCountableAbstractBadge, self).__init__(Node, field, expected_value, handler)
 
 class ActivityAbstractBadge(AbstractBadge):