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,
            'score': comment.score,
            'voted': comment.is_upvoted_by(request.user),
        }
    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)

    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 #3
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 #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,
        }
    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 __generate_comments_json(obj, user, avatar_size):
    """non-view generates json data for the post comments
    """
    models.Post.objects.precache_comments(for_posts=[obj], visitor=user)
    comments = obj._cached_comments

    # {"Id":6,"PostId":38589,"CreationDate":"an hour ago","Text":"hello there!","UserDisplayName":"Jarrod Dixon","UserUrl":"/users/3/jarrod-dixon","DeleteUrl":null}
    json_comments = []
    for comment in comments:

        if user and user.is_authenticated():
            try:
                user.assert_can_delete_comment(comment)
                #/posts/392845/comments/219852/delete
                #todo translate this url
                is_deletable = True
            except exceptions.PermissionDenied:
                is_deletable = False
            is_editable = template_filters.can_edit_comment(user, comment)
        else:
            is_deletable = False
            is_editable = False

        comment_owner = comment.author
        tz = ' ' + template_filters.TIMEZONE_STR
        comment_data = {
            'id': comment.id,
            'object_id': obj.id,
            'comment_added_at':
            str(comment.added_at.replace(microsecond=0)) + tz,
            'html': comment.html,
            'user_display_name': escape(comment_owner.username),
            'user_profile_url': comment_owner.get_profile_url(),
            'user_avatar_url': comment_owner.get_avatar_url(avatar_size),
            'user_id': comment_owner.id,
            'user_is_administrator': comment_owner.is_administrator(),
            'user_is_moderator': comment_owner.is_moderator(),
            'is_deletable': is_deletable,
            'is_editable': is_editable,
            'points': comment.points,
            'score': comment.points,  #to support js
            'upvoted_by_user': getattr(comment, 'upvoted_by_user', False)
        }
        json_comments.append(comment_data)

    data = simplejson.dumps(json_comments)
    return HttpResponse(data, content_type="application/json")
Example #11
0
def __generate_comments_json(obj, user, avatar_size):
    """non-view generates json data for the post comments
    """
    models.Post.objects.precache_comments(for_posts=[obj], visitor=user)
    comments = obj._cached_comments

    # {"Id":6,"PostId":38589,"CreationDate":"an hour ago","Text":"hello there!","UserDisplayName":"Jarrod Dixon","UserUrl":"/users/3/jarrod-dixon","DeleteUrl":null}
    json_comments = []
    for comment in comments:

        if user and user.is_authenticated():
            try:
                user.assert_can_delete_comment(comment)
                #/posts/392845/comments/219852/delete
                #todo translate this url
                is_deletable = True
            except exceptions.PermissionDenied:
                is_deletable = False
            is_editable = template_filters.can_edit_comment(user, comment)
        else:
            is_deletable = False
            is_editable = False


        comment_owner = comment.author
        tz = ' ' + template_filters.TIMEZONE_STR
        comment_data = {'id' : comment.id,
            'object_id': obj.id,
            'comment_added_at': str(comment.added_at.replace(microsecond = 0)) + tz,
            'html': comment.html,
            'user_display_name': escape(comment_owner.username),
            'user_profile_url': comment_owner.get_profile_url(),
            'user_avatar_url': comment_owner.get_avatar_url(avatar_size),
            'user_id': comment_owner.id,
            'user_is_administrator': comment_owner.is_administrator(),
            'user_is_moderator': comment_owner.is_moderator(),
            'is_deletable': is_deletable,
            'is_editable': is_editable,
            'points': comment.points,
            'score': comment.points, #to support js
            'upvoted_by_user': getattr(comment, 'upvoted_by_user', False)
        }
        json_comments.append(comment_data)

    data = simplejson.dumps(json_comments)
    return HttpResponse(data, content_type="application/json")
Example #12
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 #13
0
def __generate_comments_json(obj, user):  # non-view generates json data for the post comments
    """non-view generates json data for the post comments
    """
    models.Post.objects.precache_comments(for_posts=[obj], visitor=user)
    comments = obj._cached_comments

    # {"Id":6,"PostId":38589,"CreationDate":"an hour ago","Text":"hello there!","UserDisplayName":"Jarrod Dixon","UserUrl":"/users/3/jarrod-dixon","DeleteUrl":null}
    json_comments = []
    for comment in comments:

        if user and user.is_authenticated():
            try:
                user.assert_can_delete_comment(comment)
                # /posts/392845/comments/219852/delete
                # todo translate this url
                is_deletable = True
            except exceptions.PermissionDenied:
                is_deletable = False
            is_editable = template_filters.can_edit_comment(comment.author, comment)
        else:
            is_deletable = False
            is_editable = False

        comment_owner = comment.author
        comment_data = {
            "id": comment.id,
            "object_id": obj.id,
            "comment_age": diff_date(comment.added_at),
            "html": comment.html,
            "user_display_name": comment_owner.username,
            "user_url": comment_owner.get_profile_url(),
            "user_id": comment_owner.id,
            "is_deletable": is_deletable,
            "is_editable": is_editable,
            "score": comment.score,
            "upvoted_by_user": getattr(comment, "upvoted_by_user", False),
        }
        json_comments.append(comment_data)

    data = simplejson.dumps(json_comments)
    return HttpResponse(data, mimetype="application/json")
Example #14
0
def __generate_comments_json(
        obj, user):  #non-view generates json data for the post comments
    """non-view generates json data for the post comments
    """
    comments = obj.get_comments(visitor=user)
    # {"Id":6,"PostId":38589,"CreationDate":"an hour ago","Text":"hello there!","UserDisplayName":"Jarrod Dixon","UserUrl":"/users/3/jarrod-dixon","DeleteUrl":null}
    json_comments = []
    for comment in comments:

        if user != None and user.is_authenticated():
            try:
                user.assert_can_delete_comment(comment)
                #/posts/392845/comments/219852/delete
                #todo translate this url
                is_deletable = True
            except exceptions.PermissionDenied:
                is_deletable = False
            is_editable = template_filters.can_edit_comment(
                comment.user, comment)
        else:
            is_deletable = False
            is_editable = False

        comment_owner = comment.get_owner()
        comment_data = {
            'id': comment.id,
            'object_id': obj.id,
            'comment_age': diff_date(comment.added_at),
            'html': comment.html,
            'user_display_name': comment_owner.username,
            'user_url': comment_owner.get_profile_url(),
            'user_id': comment_owner.id,
            'is_deletable': is_deletable,
            'is_editable': is_editable,
            'score': comment.score,
            'upvoted_by_user': getattr(comment, 'upvoted_by_user', False)
        }
        json_comments.append(comment_data)

    data = simplejson.dumps(json_comments)
    return HttpResponse(data, mimetype="application/json")
Example #15
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 #16
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 #17
0
def __generate_comments_json(obj, user):#non-view generates json data for the post comments
    """non-view generates json data for the post comments
    """
    comments = obj.comments.all().order_by('id')
    # {"Id":6,"PostId":38589,"CreationDate":"an hour ago","Text":"hello there!","UserDisplayName":"Jarrod Dixon","UserUrl":"/users/3/jarrod-dixon","DeleteUrl":null}
    json_comments = []
    for comment in comments:

        if user != None and user.is_authenticated():
            try:
                user.assert_can_delete_comment(comment)
                #/posts/392845/comments/219852/delete
                #todo translate this url
                is_deletable = True
            except exceptions.PermissionDenied:
                is_deletable = False
            is_editable = template_filters.can_edit_comment(comment.user, comment)
        else:
            is_deletable = False
            is_editable = False


        comment_owner = comment.get_owner()
        json_comments.append({'id' : comment.id,
            'object_id': obj.id,
            'comment_age': diff_date(comment.added_at),
            'html': comment.html,
            'user_display_name': comment_owner.username,
            'user_url': comment_owner.get_profile_url(),
            'user_id': comment_owner.id,
            'is_deletable': is_deletable,
            'is_editable': is_editable,
        })

    data = simplejson.dumps(json_comments)
    return HttpResponse(data, mimetype="application/json")