]> git.openstreetmap.org Git - osqa.git/commitdiff
#OSQA-388, creating a separate action for the award points for an answer functionality.
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 23 Mar 2011 23:34:06 +0000 (23:34 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 23 Mar 2011 23:34:06 +0000 (23:34 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@880 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/actions/user.py
forum/views/commands.py

index 5b818c72a4ca4e4ca71dab5d7a361f8ca713d99b..f9a9913918a3d9899019808098c4359ad08d83aa 100644 (file)
@@ -88,6 +88,43 @@ class BonusRepAction(ActionProxy):
         except Exception, e:
             return ''
 
+class AwardPointsAction(ActionProxy):
+    verb = _("gave reputation points")
+
+    def process_data(self, value, affected):
+        self._value = value
+        self._affected = affected
+
+
+    def repute_users(self):
+        self.repute(self._affected, self._value)
+
+        if self._value > 0:
+            self._affected.message_set.create(
+                    message=_("Congratulations, you have been awarded an extra %s reputation points.") % self._value +
+                    '<br />%s' % self.extra.get('message', _('Thank you')))
+        else:
+            self._affected.message_set.create(
+                    message=_("You gave %s reputation points.") % self._value +
+                    '<br />%s' % self.extra.get('message', ''))
+
+    def describe(self, viewer=None):
+        value = self.extra.get('value', _('unknown'))
+
+        try:
+            if int(value) > 0:
+                return _("%(user)s awarded an extra %(value)s reputation points to %(users)s") % {
+                'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),
+                'value': value, 'users':self.affected_links(viewer),
+                }
+            else:
+                return _("%(user)s penalised %(users)s in %(value)s reputation points") % {
+                'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),
+                'value': value, 'users':self.affected_links(viewer),
+                }
+        except Exception, e:
+            return ''
+
 class AwardAction(ActionProxy):
     verb = _("was awarded")
 
index f7d91aefd89e60b56942699dd0e5734c5f7cc27b..ae773bdd23476a9d0e0f0314afde7555ac8ffbf6 100644 (file)
@@ -577,9 +577,9 @@ def award_points(request, user_id, answer_id):
         extra = dict(message=request.POST.get('message', ''), awarding_user=request.user.id, value=points)
 
         # We take points from the awarding user
-        BonusRepAction(user=request.user, extra=extra).save(data=dict(value=-points, affected=user))
+        AwardPointsAction(user=request.user, extra=extra).save(data=dict(value=-points, affected=user))
 
         # And give them to the awarded one
-        BonusRepAction(user=request.user, extra=extra).save(data=dict(value=points, affected=awarded_user))
+        AwardPointsAction(user=request.user, extra=extra).save(data=dict(value=points, affected=awarded_user))
 
         return { 'message' : _("You have awarded %s with %d points") % (awarded_user, points) }