(request, experiment_name)
return render(request, 'ajax_response.html', context={
        'comparisons': comparisons,
        'experiment': _build_experiment_resource(experiment_name)
    })
Update a comparison with a response
Update a comparison with a response
Update a comparison with a response
def ajax_response(request, experiment_name):
    """Update a comparison with a response"""

    POST = request.POST
    comparison_id = POST.get("comparison_id")
    debug = True

    comparison = Comparison.objects.get(pk=comparison_id)

    # Update the values
    comparison.response = POST.get("response")
    comparison.responded_at = timezone.now()

    if debug:
        print("Answered comparison {} with {}".format(comparison_id, comparison.response))

    comparison.full_clean()  # Validation
    comparison.save()

    comparisons = list(_all_comparisons(experiment_name)[:1])
    for comparison in comparisons: display_comparison(comparison)
    if debug:
        print("{}".format([x.id for x in comparisons]))
        if comparison:
            print("Requested {}".format(comparison.id))
    return render(request, 'ajax_response.html', context={
        'comparisons': comparisons,
        'experiment': _build_experiment_resource(experiment_name)
    })
def ajax_response ( request , experiment_name ) : POST = request . POST comparison_id = POST . get ( "comparison_id" ) debug = True comparison = Comparison . objects . get ( pk = comparison_id ) # Update the values comparison . response = POST . get ( "response" ) comparison . responded_at = timezone . now ( ) if debug : print ( "Answered comparison {} with {}" . format ( comparison_id , comparison . response ) ) comparison . full_clean ( ) # Validation comparison . save ( ) comparisons = list ( _all_comparisons ( experiment_name ) [ : 1 ] ) for comparison in comparisons : display_comparison ( comparison ) if debug : print ( "{}" . format ( [ x . id for x in comparisons ] ) ) if comparison : print ( "Requested {}" . format ( comparison . id ) ) return render ( request , 'ajax_response.html' , context = { 'comparisons' : comparisons , 'experiment' : _build_experiment_resource ( experiment_name ) } )