使用Django提交Mturk响应

时间:2015-07-06 16:36:07

标签: django amazon-web-services boto mechanicalturk

我正在尝试将Mechanical Turk任务提交回我的Django应用程序和Amazon Mturk站点。它适用于我的Django应用程序,但我无法将其提交回Amazon Mturk站点。 “提交HIT”按钮也不可用。

我尝试过在Javascript中向亚马逊提交并在Django视图中提交给亚马逊,但都没有工作。在任何时候都不会突出显示“提交HIT”按钮。

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"

1 个答案:

答案 0 :(得分:1)

找出问题所在。我刚刚更改了以下几行:

使用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 }}">

编辑:亚马逊“提交HIT”按钮不可用,因为Mturk问题是一个外部问题(通过Boto提交):

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