Esempio n. 1
0
def contact_worker(request, aid):
    mturk_permission = check_mturk_access(request)

    if mturk_permission == False:
        return HttpResponseForbidden()

    assignment = Assignment.objects.get(id=aid)
    worker = assignment.worker
    if request.method == "GET":
        form = WorkerContactForm()
        context = {
            "form": form,
            "worker": worker,
            "assignment": assignment
        }
        return render(request, "turk/contact_worker_modal.html", context)
    elif request.method == "POST":
        form = WorkerContactForm(request.POST)
        if form.is_valid():
            AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY_ID = get_credentials(
                battery=assignment.hit.battery
            )
            conn = get_connection(
                AWS_ACCESS_KEY_ID,
                AWS_SECRET_ACCESS_KEY_ID,
                hit=assignment.hit
            )
            subject = form.cleaned_data['subject']
            message = form.cleaned_data['message']
            conn.notify_workers([worker.id], subject, message)
            return redirect('manage_hit', bid=assignment.hit.battery.id, 
                            hid=assignment.hit.id)
    else:
        return HttpResponseNotAllowed()
Esempio n. 2
0
def init_connection_callback(sender, **signal_args):
    """Mechanical Turk connection signal callback

    By using Django pre-init signals, class level connections can be
    made available to Django models that configure this pre-init
    signal.
    """
    sender.args = sender
    object_args = signal_args['kwargs']
    sender.connection = get_connection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY_ID)
Esempio n. 3
0
 def generate_connection(self):
     # Get the aws access id from the credentials file
     AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY_ID = get_credentials(battery=self.battery)
     self.connection = get_connection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY_ID,hit=self)
Esempio n. 4
0
 def generate_connection(self):
     self.connection = get_connection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY_ID)
     self.save()