Sal
Sal

Reputation: 1693

Submitting Mturk response with Django

I am trying to submit a Mechanical Turk task back to both my Django application and to the Amazon Mturk site. It works fine with my Django application but I can't get it to submit back to the Amazon Mturk site. The "Submit HIT" button isn't available either.

I've tried just submitting to Amazon in the Javascript and submitting to Amazon inside the Django view, but neither work. At no point is the "Submit HIT" button highlighted.

enter image description here

HTML:

<form id="task_form"  method="POST">
    {% csrf_token %}
    <input type="hidden" name="id" value="{{ hit_id }}" />
    <input type="hidden" name="assignmentId" value="{{ assignment_id }}" />
    <input type="hidden" name="workerId" value="{{ worker_id }}" />
    <input type="hidden" id="task_score" name="task_score" value="" />
    <input type="radio" name="outcome_class" onclick="showCausal()" value="{{ s.class1_name }}">
</form>
<input class="btn btn-primary" type="submit" name="submit" id="submit_task_button2"/>

Javascript:

<script type="text/javascript">
    $(function(){
        $("#submit_task_button2").click(function(){
                var a = $('#slider_vals').slider("option", "value")
                document.getElementById("task_score").setAttribute('value', a);
                $.post("{% url 'task' %}", $('#task_form').serialize());
                $.post("{{ amazon_host }}", $('#task_form').serialize());   
            });
        });
</script>

Django:

def task_view(request):
    if request.method == 'POST':
        now_banned = False
        warning = False
        print request.POST
        task = Tasks.objects.get(mturk_hit_id = request.session['hit_id'])

        task.finished_at = timezone.now()
        task.updated_at = timezone.now()
        task.chosen_confidence = int(request.POST['task_score']) + 1
        task.chosen_outcome = request.POST['outcome_class']

        task.turker_comments = request.POST['turker_comments-input']
        task.save()
        request.session.clear()
    ...
    ...
    amazon_host = request.GET.get("turkSubmitTo", "") + "/mturk/externalSubmit"

Upvotes: 1

Views: 286

Answers (1)

Sal
Sal

Reputation: 1693

Figured out the problem. I just changed the following lines:

Javascript:

<script type="text/javascript">
        $(function(){
            $("#submit_task_button2").click(function(){
                var a = $('#slider_vals').slider("option", "value")
                document.getElementById("task_score").setAttribute('value', a);
                $('#task_form').submit();
                $.post("{% url 'task' %}", $('#task_form').serialize());
            });
        });
</script>

HTML:

<form id="task_form"  method="POST" action="{{ amazon_host }}">

EDIT: The Amazon "Submit HIT" button isn't available because the Mturk question is an External Question (submitted via Boto):

boto.mturk.question.ExternalQuestion( URL, FRAME_HEIGHT )

Upvotes: 1

Related Questions