Ejemplo n.º 1
0
def post_comment(request, proposal_id, field):
    user = _get_current_user(request)
    proposal = Proposal.objects.get(id=proposal_id)
    
    form = CommentForm(request.POST) # A form bound to the POST data
    if "actionComment" in request.POST:
        commentType = "action"
    elif "backgroundComment" in request.POST:
        commentType = "background"
    elif "beliefsComment" in request.POST:
        commentType = "beliefs"

    if form.is_valid(): # All validation rules pass
        # Process the data in form.cleaned_data
        comment = form.save(commit=False)
        comment.user = user
        comment.date = datetime.datetime.now()
        comment.proposal = proposal
        comment.field = commentType
        comment.save()
    else:
        # TODO Invalid comment?
        pass
    
    return get_comments(request, proposal_id, field)
Ejemplo n.º 2
0
def proposal(request, proposalId):
    user = _get_current_user(request)
    proposal = Proposal.objects.get(id=proposalId)
    comments = Comment.objects.all().filter(proposal = proposal)
    action_comments = comments.filter(field = "action")
    background_comments = comments.filter(field = "background")
    beliefs_comments = comments.filter(field = "beliefs")

    # TODO duplication currently for graceful deprecation
    
    if request.method == 'POST': # If the form has been submitted...
        form = CommentForm(request.POST) # A form bound to the POST data
        if "actionComment" in request.POST:
            commentType = "action"
        elif "backgroundComment" in request.POST:
            commentType = "background"
        elif "beliefsComment" in request.POST:
            commentType = "beliefs"

        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            comment = form.save(commit=False)
            comment.user = user
            comment.date = datetime.datetime.now()
            comment.proposal = proposal
            comment.field = commentType
            comment.save()
            return HttpResponseRedirect('/thanks/') # Redirect after POST
    else:
        form = CommentForm() # An unbound form
        return render(request, "proposal.html", {"form": form, "proposal": proposal, "action_comments" : action_comments, "background_comments" : background_comments, "beliefs_comments" : beliefs_comments, "user" : user})