示例#1
0
    def post(self, request, *args, **kwargs):
        self.comment_obj = get_object_or_404(Comment, id=request.POST.get("commentid"))
        if request.user == self.comment_obj.commented_by:
            form = ContactCommentForm(request.POST, instance=self.comment_obj)
            if form.is_valid():
                return self.form_valid(form)

            return self.form_invalid(form)

        data = {"error": "You don't have permission to edit this comment."}
        return JsonResponse(data)
示例#2
0
def edit_comment(request):
    if request.method == "POST":
        comment = request.POST.get('comment')
        comment_id = request.POST.get("commentid")
        com = get_object_or_404(Comment, id=comment_id)
        form = ContactCommentForm(request.POST)
        if request.user == com.commented_by:
            if form.is_valid():
                com.comment = comment
                com.save()
                data = {"comment": com.comment, "commentid": comment_id}
                return JsonResponse(data)
            else:
                return JsonResponse({"error": form['comment'].errors})
        else:
            return JsonResponse({"error": "You dont have authentication to edit"})
    else:
        return render(request, "404.html")
示例#3
0
def add_comment(request):
    if request.method == 'POST':
        contact = get_object_or_404(Contact, id=request.POST.get('contactid'))
        if request.user in contact.assigned_to.all() or request.user == contact.created_by:
            form = ContactCommentForm(request.POST)
            if form.is_valid():
                contact_comment = form.save(commit=False)
                contact_comment.comment = request.POST.get('comment')
                contact_comment.commented_by = request.user
                contact_comment.contact = contact
                contact_comment.save()
                data = {"comment_id": contact_comment.id, "comment": contact_comment.comment,
                        "commented_on": contact_comment.commented_on,
                        "commented_by": contact_comment.commented_by.email}
                return JsonResponse(data)
            else:
                return JsonResponse({"error": form['comment'].errors})
        else:
            data = {'error': "You Dont Have permissions to Comment"}
            return JsonResponse(data)