]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/commands.py
Makes tips on the ask a question page editable in the admin.
[osqa.git] / forum / views / commands.py
index a447ffefb79c27ac6c3f2bc711f49b14629f38f4..f7d91aefd89e60b56942699dd0e5734c5f7cc27b 100644 (file)
@@ -555,6 +555,7 @@ def answer_permanent_link(request, id):
 def award_points(request, user_id, answer_id):
     user = request.user
     awarded_user = get_object_or_404(User, id=user_id)
+    answer = get_object_or_404(Answer, id=answer_id)
 
     # Users shouldn't be able to award themselves
     if awarded_user.id == user.id:
@@ -564,6 +565,21 @@ def award_points(request, user_id, answer_id):
     if not user.is_authenticated():
         raise AnonymousNotAllowedException(_('award'))
 
-    return render_to_response("node/award_points.html", { 'user' : user, 'awarded_user' : awarded_user, })
-    # Display the template
-    return render_to_response('node/permanent_link.html', { 'url' : url, })
+    if not request.POST:
+        return render_to_response("node/award_points.html", { 'user' : user, 'awarded_user' : awarded_user, })
+    else:
+        points = int(request.POST['points'])
+
+        # We should check if the user has enough reputation points, otherwise we raise an exception.
+        if user.reputation < points:
+            raise NotEnoughRepPointsException(_("award"))
+
+        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))
+
+        # And give them to the awarded one
+        BonusRepAction(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) }