Example #1
0
def edit_comment(request):
    if request.user.is_authenticated():
        comment_id = int(request.POST['comment_id'])
        comment = models.Comment.objects.get(id=comment_id)

        request.user.edit_comment(comment=comment,
                                  body_text=request.POST['comment'])

        is_deletable = template_filters.can_delete_comment(
            comment.user, comment)
        is_editable = template_filters.can_edit_comment(comment.user, comment)

        return {
            'id': comment.id,
            'object_id': comment.content_object.id,
            'comment_age': diff_date(comment.added_at),
            'html': comment.html,
            'user_display_name': comment.user.username,
            'user_url': comment.user.get_profile_url(),
            'user_id': comment.user.id,
            'is_deletable': is_deletable,
            'is_editable': is_editable,
        }
    else:
        raise exceptions.PermissionDenied(
            _('Sorry, anonymous users cannot edit comments'))
Example #2
0
def edit_comment(request):
    if request.user.is_anonymous():
        raise exceptions.PermissionDenied(
            _('Sorry, anonymous users cannot edit comments'))

    comment_id = int(request.POST['comment_id'])
    comment_post = models.Post.objects.get(post_type='comment', id=comment_id)

    request.user.edit_comment(comment_post=comment_post,
                              body_text=request.POST['comment'])

    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

    return {
        'id': comment_post.id,
        'object_id': comment_post.parent.id,
        'comment_added_at':
        str(comment_post.added_at.replace(microsecond=0)) + tz,
        'html': comment_post.html,
        'user_display_name': 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.score,
        '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'))

    comment_id = int(request.POST['comment_id'])
    comment_post = models.Post.objects.get(post_type='comment', id=comment_id)

    request.user.edit_comment(comment_post=comment_post, body_text = request.POST['comment'])

    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

    return {
        'id' : comment_post.id,
        'object_id': comment_post.parent.id,
        'comment_added_at': str(comment_post.added_at.replace(microsecond = 0)) + tz,
        'html': comment_post.html,
        'user_display_name': 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.score,
        'voted': comment_post.is_upvoted_by(request.user),
    }
Example #4
0
def edit_comment(request):
    if request.user.is_anonymous():
        raise exceptions.PermissionDenied(_("Sorry, anonymous users cannot edit comments"))

    comment_id = int(request.POST["comment_id"])
    comment_post = models.Post.objects.get(post_type="comment", id=comment_id)

    request.user.edit_comment(comment_post=comment_post, body_text=request.POST["comment"])

    is_deletable = template_filters.can_delete_comment(comment_post.author, comment_post)
    is_editable = template_filters.can_edit_comment(comment_post.author, comment_post)

    return {
        "id": comment_post.id,
        "object_id": comment_post.parent.id,
        "comment_age": diff_date(comment_post.added_at),
        "html": comment_post.html,
        "user_display_name": 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.score,
        "voted": comment_post.is_upvoted_by(request.user),
    }
Example #5
0
def edit_comment(request):
    if request.user.is_authenticated():
        comment_id = int(request.POST['comment_id'])
        comment = models.Comment.objects.get(id = comment_id)

        request.user.edit_comment(
                        comment = comment,
                        body_text = request.POST['comment']
                    )

        is_deletable = template_filters.can_delete_comment(comment.user, comment)
        is_editable = template_filters.can_edit_comment(comment.user, comment)

        return {'id' : comment.id,
            'object_id': comment.content_object.id,
            'comment_age': diff_date(comment.added_at),
            'html': comment.html,
            'user_display_name': comment.user.username,
            'user_url': comment.user.get_profile_url(),
            'user_id': comment.user.id,
            'is_deletable': is_deletable,
            'is_editable': is_editable,
            'score': comment.score,
            'voted': comment.is_upvoted_by(request.user),
        }
    else:
        raise exceptions.PermissionDenied(
                _('Sorry, anonymous users cannot edit comments')
            )
Example #6
0
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),
    }
Example #7
0
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),
    }
Example #8
0
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"])

    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),
    }
Example #9
0
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),
    }
Example #10
0
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),
    }
Example #11
0
def edit_comment(request):
    if request.user.is_anonymous():
        raise exceptions.PermissionDenied(_('Sorry, anonymous users cannot edit comments'))

    form = forms.EditCommentForm(request.POST)
    if form.is_valid() == False:
        return HttpResponseBadRequest()
        
    comment_id = form.cleaned_data['comment_id']
    suppress_email = form.cleaned_data['suppress_email']

    comment_post = models.Post.objects.get(post_type='comment', id=comment_id)

    request.user.edit_comment(
        comment_post=comment_post,
        body_text = request.POST['comment'],
        suppress_email=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

    return {
        'id' : comment_post.id,
        'object_id': comment_post.parent.id,
        'comment_added_at': str(comment_post.added_at.replace(microsecond = 0)) + tz,
        'html': comment_post.html,
        'user_display_name': 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),
    }
Example #12
0
def edit_comment(request):
    if request.user.is_authenticated():
        comment_id = int(request.POST["comment_id"])
        comment = models.Comment.objects.get(id=comment_id)

        request.user.edit_comment(comment=comment, body_text=request.POST["comment"])

        is_deletable = template_filters.can_delete_comment(comment.user, comment)
        is_editable = template_filters.can_edit_comment(comment.user, comment)

        return {
            "id": comment.id,
            "object_id": comment.content_object.id,
            "comment_age": diff_date(comment.added_at),
            "html": comment.html,
            "user_display_name": comment.user.username,
            "user_url": comment.user.get_profile_url(),
            "user_id": comment.user.id,
            "is_deletable": is_deletable,
            "is_editable": is_editable,
        }
    else:
        raise exceptions.PermissionDenied(_("Sorry, anonymous users cannot edit comments"))