Exemplo n.º 1
0
def new_comment(request, pk):
    proposal = get_object_or_404(Proposal, pk=pk)

    # redirect if comments are not allowed
    if not proposal.theme.track.allow_comments:
        return redirect('review:proposal', pk=proposal.pk)

    # if valid post...
    if request.method == "POST":
        form = EditCommentForm(request.POST)
        if form.is_valid():

            # save the comment
            comment = form.save(commit=False)
            comment.proposal = proposal
            comment.created_by = request.user
            comment.save()
            return redirect('review:proposal', pk=proposal.pk)
        else:
            #show errors
            messages.error(request, 'Please correct the errors below.')
    else:
        form = EditCommentForm()
    return render(request, 'review/comments/new_comment.html', {
        'proposal': proposal,
        'form': form
    })