- 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,
+ 'reputation_to_comment' : str(settings.REP_TO_COMMENT)
+ })
+ else:
+ points = int(request.POST['points'])
+
+ # We should check if the user has enough reputation points, otherwise we raise an exception.
+ if points < 0:
+ raise CommandException(_("The number of points to award needs to be a positive value."))
+
+ 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
+ AwardPointsAction(user=request.user, node=answer, extra=extra).save(data=dict(value=points, affected=awarded_user))
+
+ return { 'message' : _("You have awarded %(awarded_user)s with %(points)d points") % {'awarded_user' : awarded_user, 'points' : points} }
+