Beispiel #1
0
def delete(request, comment_id):
    comment = get_object_or_404(Comment, pk=comment_id)
    report = comment.report
    if request.method == "POST":
        if can_edit_comment(request.user, comment):
            comment.delete()
            messages.success(request, "Comment Deleted")
        else:
            messages.warning(request, "Comment Is Not Yours To Edit")
        return redirect("reports-detail", report.pk)

    related_objects = list(will_be_deleted_with(comment))

    return render(request, "delete.html", {"object": comment, "will_be_deleted_with": related_objects})
Beispiel #2
0
def delete(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    if request.method == "POST":
        user.delete()
        messages.success(request, "User deleted!")
        return redirect("users-list")

    related_objects = list(will_be_deleted_with(user))

    return render(request, "delete.html", {
        # we don't call this template variable "user" because that collides
        # with the "user" variable which references the currently logged in
        # user
        "object": user,
        "will_be_deleted_with": related_objects,
    })
Beispiel #3
0
def delete(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    if request.method == "POST":
        user.delete()
        messages.success(request, "User deleted!")
        return redirect("users-list")

    related_objects = list(will_be_deleted_with(user))

    return render(
        request,
        "delete.html",
        {
            # we don't call this template variable "user" because that collides
            # with the "user" variable which references the currently logged in
            # user
            "object": user,
            "will_be_deleted_with": related_objects,
        })
    def get_context_data(self, **kwargs):
        obj = super(DeleteView, self).get_object()
        context = super(CategoryDeleteView, self).get_context_data(**kwargs)
        context['will_be_deleted_with'] = will_be_deleted_with(obj)

        return context