def edit_comment(request): if request.user.is_anonymous(): raise exceptions.PermissionDenied(_('Sorry, anonymous users cannot edit comments')) if askbot_settings.READ_ONLY_MODE_ENABLED: raise exceptions.PermissionDenied(askbot_settings.READ_ONLY_MESSAGE) form = forms.EditCommentForm(request.POST) if form.is_valid() == False: raise exceptions.PermissionDenied('This content is forbidden') if akismet_check_spam(form.cleaned_data['comment'], request): raise exceptions.PermissionDenied(_( 'Spam was detected on your post, sorry ' 'for if this is a mistake' )) comment_post = models.Post.objects.get( post_type='comment', id=form.cleaned_data['comment_id'] ) revision = request.user.edit_comment( comment_post=comment_post, body_text=form.cleaned_data['comment'], suppress_email=form.cleaned_data['suppress_email'], ip_addr=request.META.get('REMOTE_ADDR'), ) is_deletable = template_filters.can_delete_comment( comment_post.author, comment_post) is_editable = template_filters.can_edit_comment( comment_post.author, comment_post) tz = ' ' + template_filters.TIMEZONE_STR tz = template_filters.TIMEZONE_STR timestamp = str(comment_post.added_at.replace(microsecond=0)) + tz #need this because the post.text is due to the latest approved #revision, but we may need the suggested revision comment_post.text = revision.text comment_post.html = comment_post.parse_post_text()['html'] return { 'id' : comment_post.id, 'object_id': comment_post.parent.id, 'comment_added_at': timestamp, 'html': comment_post.html, 'user_display_name': escape(comment_post.author.username), 'user_url': comment_post.author.get_profile_url(), 'user_id': comment_post.author.id, 'is_deletable': is_deletable, 'is_editable': is_editable, 'score': comment_post.points, #to support unchanged js 'points': comment_post.points, 'voted': comment_post.is_upvoted_by(request.user), }
def edit_comment(request): if request.user.is_anonymous(): raise exceptions.PermissionDenied( _('Sorry, anonymous users cannot edit comments')) if askbot_settings.READ_ONLY_MODE_ENABLED: raise exceptions.PermissionDenied(askbot_settings.READ_ONLY_MESSAGE) form = forms.EditCommentForm(request.POST) if form.is_valid() == False: raise exceptions.PermissionDenied('This content is forbidden') comment_post = models.Post.objects.get(post_type='comment', id=form.cleaned_data['comment_id']) request.user.edit_comment( comment_post=comment_post, body_text=form.cleaned_data['comment'], suppress_email=form.cleaned_data['suppress_email']) is_deletable = template_filters.can_delete_comment(comment_post.author, comment_post) is_editable = template_filters.can_edit_comment(comment_post.author, comment_post) tz = ' ' + template_filters.TIMEZONE_STR tz = template_filters.TIMEZONE_STR timestamp = str(comment_post.added_at.replace(microsecond=0)) + tz return { 'id': comment_post.id, 'object_id': comment_post.parent.id, 'comment_added_at': timestamp, 'html': comment_post.html, 'user_display_name': escape(comment_post.author.username), 'user_url': comment_post.author.get_profile_url(), 'user_id': comment_post.author.id, 'is_deletable': is_deletable, 'is_editable': is_editable, 'score': comment_post.points, #to support unchanged js 'points': comment_post.points, 'voted': comment_post.is_upvoted_by(request.user), }