Exemplo n.º 1
0
def add_comment(request):
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save()
            return render_json({"comment": comment.to_dict()})
        else:
            return render_json(error=[{"field": k, "error": unicode(v[0])} for k, v in form.errors.items()])
Exemplo n.º 2
0
def edit_comment(request, comment_id):
    comment = ReferenceComment.objects.get(pk=comment_id)
    if request.method == "POST":
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            comment = form.save()
            return render_json({"comment": comment.to_dict()})
        else:
            return render_json(error=[{"field": k, "error": unicode(v[0])} for k, v in form.errors.items()])
Exemplo n.º 3
0
def edit_comment(request, comment_id):
    comment = get_object_or_404(ReferenceComment, pk=comment_id, user=request.user)
    form = CommentForm(instance=comment)
    if request.method == 'POST':
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            comment = form.save()
            return redirect(reverse('view_reference', args=[comment.reference.slug]))

    return render(request, 'comments/edit_comment.html', {
        'form': form,
    })