Ticket #1659: karma.2.diff
File karma.2.diff, 1.5 KB (added by , 19 years ago) |
---|
-
karma.py
1 1 from django.http import Http404 2 2 from django.shortcuts import render_to_response 3 3 from django.template import RequestContext 4 from django. models.comments import comments, karma4 from django.contrib.comments.models import Comment, KarmaScore 5 5 6 6 def vote(request, comment_id, vote): 7 7 """ … … 18 18 if request.user.is_anonymous(): 19 19 raise Http404, _("Anonymous users cannot vote") 20 20 try: 21 comment = comments.get_object(pk=comment_id)22 except comments.CommentDoesNotExist:21 comment = Comment.objects.get(pk=comment_id) 22 except Comment.DoesNotExist: 23 23 raise Http404, _("Invalid comment ID") 24 if comment.user _id == request.user.id:24 if comment.user.id == request.user.id: 25 25 raise Http404, _("No voting for yourself") 26 karma.vote(request.user.id, comment_id, rating)26 KarmaScore.objects.vote(request.user.id, comment_id, rating) 27 27 # Reload comment to ensure we have up to date karma count 28 comment = comments.get_object(pk=comment_id)29 return render_to_response('comments/karma_vote_accepted ', {'comment': comment}, context_instance=RequestContext(request))28 comment = Comment.objects.get(pk=comment_id) 29 return render_to_response('comments/karma_vote_accepted.html', {'comment': comment}, context_instance=RequestContext(request))