Example #1
0
def delete_my_comment(request, comment_id):
    """
    Provide user to delete his own comment.
    Note: We are not removing the comment in the database!
    We are just setting comment field `comment.is_removed = True`

    Thus if anyone re-comment the same "exact" comment previously posted,
    will not be saved!

    django.contrib.comments.views.moderation.delete()
    provides Moderators to perform this operation!
    """ 
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    if request.method == 'POST' and \
        request.is_ajax():
        data = {}
        comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)
        if request.user == comment.user:
            perform_delete(request, comment)
            data['success'] = True
        else:
            raise Http404
        return HttpResponse(simplejson.dumps(data), mimetype="application/json")

    else:
        raise Http404
Example #2
0
 def save(self, commit=True):
     if self.cleaned_data['APPROVE']:
         perform_approve(self.formset.request, self.instance)
         self.formset.actions.add(self.instance)
     elif self.cleaned_data['REMOVE']:
         perform_delete(self.formset.request, self.instance)
         self.formset.actions.add(self.instance)
 def save(self, commit=True):
     if self.cleaned_data['APPROVE']:
         perform_approve(self.formset.request, self.instance)
         self.formset.actions.add(self.instance)
     elif self.cleaned_data['REMOVE']:
         perform_delete(self.formset.request, self.instance)
         self.formset.actions.add(self.instance)
Example #4
0
def delete_my_comment(request, comment_id):
    """
    Provide user to delete his own comment.
    Note: We are not removing the comment in the database!
    We are just setting comment field `comment.is_removed = True`

    Thus if anyone re-comment the same "exact" comment previously posted,
    will not be saved!

    django.contrib.comments.views.moderation.delete()
    provides Moderators to perform this operation!
    """
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    if request.method == 'POST' and \
        request.is_ajax():
        data = {}
        comment = get_object_or_404(comments.get_model(),
                                    pk=comment_id,
                                    site__pk=settings.SITE_ID)
        if request.user == comment.user:
            perform_delete(request, comment)
            data['success'] = True
        else:
            raise Http404
        return HttpResponse(simplejson.dumps(data),
                            mimetype="application/json")

    else:
        raise Http404
Example #5
0
def delete_recipe_comment(request, recipe_id, comment_id):
    comment = get_object_or_404(comments.get_model(), pk=comment_id)
    if comment.user == request.user:
        perform_delete(request, comment)
        messages.add_message(request, messages.INFO, 'Je reactie werd succesvol verwijderd.')
        return redirect(view_recipe, recipe_id)
    else:
        raise PermissionDenied
def moderate(request, comment_id, next=None):
    if not request.is_ajax:
        return redirect('django.contrib.comments.views.moderation.delete', 
            comment_id)
        
    from django.contrib.comments.views.moderation import perform_delete
    comment = get_object_or_404(OslComment, pk=comment_id, 
        site__pk=settings.SITE_ID)
    perform_delete(request, comment)
    
    return redirect('osl_comments.views.get_comment', comment_id=comment_id)
Example #7
0
def delete_comment(request, comment_id):

    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)
    if request.user == comment.user:
        perform_delete(request, comment)
        comment.content_object.after_del_comments()
        messages.success(request, _("Comment deleted success"))
    else:
        messages.error(request, _("You can't delete this comment"))

    # Flag the comment as deleted instead of actually deleting it.
    return redirect(get_redir_url(request))
Example #8
0
def delete(request, comment_id, next=None):
    """
    Deletes a comment. Action on GET. Requires the "can
    moderate comments" permission.

    Context:
        comment
            the flagged `comments.comment` object
    """
    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    perform_delete(request, comment)

    return delete_done(request, next, comment)
Example #9
0
def delete(request):
    """
    Wrapper to make sure the user deleting a comment is the user who originally posted that comment.  Also gets around moderation permissions by calling perform_delete() directly.
    """
    comment = get_object_or_404(comments.get_model(), pk=request.POST.get('comment_id'), site__pk=settings.SITE_ID)
    
    if comment.user == request.user:
        django_comments_moderation.perform_delete(request, comment)
        messages.success(request, 'Your comment has been deleted')  

        # should add some error handling here if 'next' is not in request.POST
        return redirect(request.POST.get('next'))

    else:
        raise Http404
Example #10
0
def delete(request):
    """
    Wrapper to make sure the user deleting a comment is the user who originally posted that comment.  Also gets around moderation permissions by calling perform_delete() directly.
    """
    comment = get_object_or_404(comments.get_model(), pk=request.POST.get('comment_id'), site__pk=settings.SITE_ID)
    
    if comment.user == request.user:
        django_comments_moderation.perform_delete(request, comment)
        messages.success(request, 'Your comment has been deleted')  

        # should add some error handling here if 'next' is not in request.POST
        return redirect(request.POST.get('next'))

    else:
        raise Http404
Example #11
0
def comment_delete(request, comment_id, next=None):
    """
    Override the django.contrib.comments.views.moderation.delete()
    No need to have the comments.can_moderate permission
    """
    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    # Delete on POST
    if request.method == 'POST':
        # Flag the comment as deleted instead of actually deleting it.
        perform_delete(request, comment)
        return next_redirect(request, next)

    # Render a form on GET
    else:
        return render_to_response(
            'comments/delete.html',
            {'comment': comment, "next": next},
            template.RequestContext(request)
        )
Example #12
0
def delete_comment(request, comment_id):
    """
    overriding default comments app's delete, so comment owners can always
    delete their comments.
    """
    comment = get_object_or_404(Comment, pk=comment_id)
    user = request.user
    if not user.is_superuser and user != comment.user:
        return HttpResponseForbidden("Forbidden operation.")

    # Delete on POST
    if request.method == 'POST':
        # Flag the comment as deleted instead of actually deleting it.
        perform_delete(request, comment)
        return redirect(request.POST["next"])

    # Render a form on GET
    else:
        return render(request, "comments/delete.html",
                      {"comment": comment,
                       "next": request.GET.get("next", "/")})
Example #13
0
    def delete(self, request):
        """
        删除一条评论

        ``POST`` `comments/destroy <http://192.168.1.222:8080/v1/comments/create>`_

        :param id:
            某条评论的 id.
        """
        comment_id = request.POST.get("id")
        try:
            klass = comments.get_model()
            comment = klass.objects.get(pk=comment_id, site__pk=settings.SITE_ID, is_removed=False)
        except klass.DoesNotExist:
            return rc.NOT_HERE

        if request.user == comment.user:
            perform_delete(request, comment)
            comment.content_object.after_del_comments()
            return rc.accepted({"result": True})
        else:
            return rc.FORBIDDEN
Example #14
0
def delete_comment(request, comment_id):
    """
    overriding default comments app's delete, so comment owners can always
    delete their comments.
    """
    comment = get_object_or_404(Comment, pk=comment_id)
    user = request.user
    if not user.is_superuser and user != comment.user:
        return HttpResponseForbidden("Forbidden operation.")

    # Delete on POST
    if request.method == 'POST':
        # Flag the comment as deleted instead of actually deleting it.
        perform_delete(request, comment)
        return redirect(request.POST["next"])

    # Render a form on GET
    else:
        return render(request, "comments/delete.html", {
            "comment": comment,
            "next": request.GET.get("next", "/")
        })
Example #15
0
def post_delete(request, comment_id, next=None):
    """
    Deletes a comment. Confirmation on GET, action on POST. Requires the "can
    moderate comments" permission.

    Templates: :template:`comments/delete.html`,
    Context:
        comment
            the flagged `comments.comment` object
    """
    if not request.is_ajax():
        return HttpResponseBadRequest("Expecting Ajax call")
    

    # authenticate
    comment = get_object_or_404(django.contrib.comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    if(comment.user.pk != request.user.pk):
        return HttpResponseBadRequest("Not authenticated")
        

    # Delete on POST
    if request.method == 'POST':
        # Flag the comment as deleted instead of actually deleting it.
        perform_delete(request, comment)

    json_errors = []
        
    json_return = {
        'success': True,
        'errors': json_errors,
        'comment_id': comment.pk,
    }


    json_response = json.dumps(json_return)
    return HttpResponse(json_response, mimetype="application/json")
Example #16
0
def delete_comment(request, comment_id,template_name="kinger/revision/includes/comments_show.html"):
    """ 评论删除后,减少对应*瓦片*的评论数(冗余字段), 并跳转且作出提示 """
    comment = get_object_or_404(Comment, pk=comment_id, site__pk=settings.SITE_ID)
    if request.user == comment.user:
        perform_delete(request, comment)
        comment.content_object.after_del_comments()
#        messages.success(request, _("Comment deleted success"))
    else:
#        messages.error(request, _("You can't delete this comment"))
        pass
        
    tile = comment.content_object
    is_last_page = True
    if tile.n_comments > 0:
        comments = Comment.objects.for_model(tile).select_related('user')\
            .order_by("-submit_date").filter(is_public=True).filter(is_removed=False)
        if comments.count() > 5:
            is_last_page = False
    else:
        comments = None
    data = render(request, template_name,{"tile": tile,'comments':comments,"is_last_page":is_last_page})
    con=data.content
#    print con,'ccccccccccc'
    return ajax_ok('成功',con)