def upvote_comment(request): if request.user.is_anonymous(): raise exceptions.PermissionDenied(_('Please sign in to vote')) form = forms.VoteForm(request.POST) if form.is_valid(): comment_id = form.cleaned_data['post_id'] cancel_vote = form.cleaned_data['cancel_vote'] comment = models.Comment.objects.get(id=comment_id) process_vote(post=comment, vote_direction='up', user=request.user) else: raise ValueError return {'score': comment.score}
def upvote_comment(request): if request.user.is_anonymous(): raise exceptions.PermissionDenied(_('Please sign in to vote')) form = forms.VoteForm(request.POST) if form.is_valid(): comment_id = form.cleaned_data['post_id'] cancel_vote = form.cleaned_data['cancel_vote'] comment = get_object_or_404(models.Post, post_type='comment', id=comment_id) process_vote(post=comment, vote_direction='up', user=request.user) else: raise ValueError # FIXME: rename js return {'score': comment.points}
def delete_post(request): if request.user.is_anonymous(): raise exceptions.PermissionDenied( _('Please sign in to delete/restore posts')) form = forms.VoteForm(request.POST) if form.is_valid(): post_id = form.cleaned_data['post_id'] post = get_object_or_404(models.Post, post_type__in=('question', 'answer'), id=post_id) if form.cleaned_data['cancel_vote']: request.user.restore_post(post) else: request.user.delete_post(post) else: raise ValueError return {'is_deleted': post.deleted}